Reputation: 312
I have a C/C++ program x64 which uses a couple of libraries.
The compiler I use: Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64
In the beginning I did have some problems with static/dynamic linking, but I have solved these issues, and I can sucessfully compile my program with MD and MDd flags. Now, I want to get rid of the C runtime library DLLs. I would like to compile my application using MT flags.
The libraries I use: samtools, and zlib ( I use MT flag while generating both of the libraries). At the end, in the linking process I get such an error even though I have used the same configurations for all the compilation process. The error message:
LIBCMT.lib(atox.obj) : error LNK2005: atoll already defined in libbam.lib(bam_import.obj)
myApplication.exe : fatal error LNK1169: one or more multiply defined symbols found
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\x8
6_amd64\link.exe"' : return code '0x491'
commands to generate libraries and linking:
CC=cl.exe
AR= lib.exe
CFLAGS= /MT -c
INCLUDES= -I. -Iwin32
1st library:
ZLIB: $(OBJS)
$(AR) objectfiles
OBJS:
$(CC) $(CFLAGS) $(INCLUDES) sourcefiles
2nd library:
libbam.lib:$(LOBJS)
$(AR) $(LOBJS) $(BCFOBJS) /out:libbam.lib
BCFOBJ:
$(CC) $(CFLAGS) $(INCLUDES) sourcefiles
.c.obj: // LOBJS are generated here
$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
Command I use to compile my program using the libraries I produced above:
CC=cl.exe
LINK=link.exe
FLAGS= -Ox /MT -c
obj1.obj:
$(CC) $(FLAGS) test.cpp $(INCLUDES)
testMain.obj:
$(CC) $(FLAGS) testMain.cpp $(INCLUDES)
testMain.exe: $(OBJ)
$(LINK) obj1.obj testMain.obj $(LIBS) /OUT:testMain.exe
Since the makefiles are quite long, I tried to simplify it a bit, show the flags I use for each library I generate.
Thanks in advance.
Upvotes: 1
Views: 1759
Reputation: 312
I have solved the problem. Apparently, there was a function called atoll() in one of the source files I had for a required library, and while linking statically, the compiler was trying to link the system atoll() function; however, there was one of them already there. I renamed the function in all the source files, and not I can statically compile my application.
Upvotes: 1