How to stop Function name mangling with 'C' and assembler ?

Started by James Ladd, September 18, 2006, 02:10:18 AM

Previous topic - Next topic

James Ladd

I am using Gnu C and Assembler together.
I have functions in a library that are assembled and linked into a DLL.

If I don't prefix the functions with underscore "_" then the compiler / linker complains, under windows.
If I do prefix them with "_" all is ok.

However, under Linux I have the problem that when the functions are prefixed with underscore "_" the
linker can't find them. If I remove the underscores then all is ok.

Does anyone know how I can leave the underscores off the names of the functions and still have windows
assembler / link ok with them?

I have a def file and i have the names without "_" in there. Should I add an "_" ?

PBrennick

I would like to take a look at your batch file, please.
Paul
The GeneSys Project is available from:
The Repository or My crappy website

James Ladd

Actually I think this page solves the problem
http://gcc.gnu.org/ml/gcc-help/2003-10/msg00333.html

I'll have to wait to try it out on cygwin/win32 though.

Rgs, James.

Heres the makefile anyways ...


LCMD=-L. -ljlc
LEXT:=.so
ASFLAGS=-gstabs
CCFLAGS:=$(ASFLAGS)
BINS=$(patsubst %.c,%,$(wildcard test*.c))

ifeq ($(OS),Windows_NT)
LCMD:=libjlc.dll
LEXT:=.dll
ASFLAGS:=$(ASFLAGS) --defsym WIN=1
BINS:=$(patsubst %.c,%.exe,$(wildcard test*.c))
endif

all: libjlc$(LEXT) $(BINS)

libjlc.so: libjlc.o
gcc -shared -o libjlc.so $<

libjlc.dll: libjlc.o
gcc -shared -o libjlc.dll libjlc.o libjlc.def -Wl,--out-implib,libjlc.a

test%:
gcc $(CCFLAGS) -o test$* $(LCMD) $(patsubst %.exe,%,$@).c

clean:
rm -f *.so *.o *.a *.dll $(BINS)

.s.o:
as $(ASFLAGS) -o $*.o $<

Vortex

Hi James,

You can create import libraries containing symbols without the leading underscores, Pelle's Polink does the job. ( I sended you a PM )