i download a linux cmake project which i will use in the windows vs.what i do is that i create a new win32 project in vs and add all .h an .cpp file to the new project,and then,i config the third library dependence of Boost.but,there are some errors when i debug this project,the error details is as follows.
> Generating Code...
1>main.obj : error LNK2005: "struct boost::arg<1> & ibeo::placeholders::ew" (?ew#placeholders#ibeo##3AAU?$arg#$00#boost##A) already defined in libibeo.obj
1>main.obj : error LNK2005: "struct boost::arg<1> & ibeo::placeholders::points" (?points#placeholders#ibeo##3AAU?$arg#$00#boost##A) already defined in libibeo.obj
1>main.obj : error LNK2005: "struct boost::arg<1> & ibeo::placeholders::objects" (?objects#placeholders#ibeo##3AAU?$arg#$00#boost##A) already defined in libibeo.obj
1>LINK : fatal error LNK1104: cannot open file 'libboost_system-vc110-mt-gd-1_63.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
i'm using chilkat and libcurl in same project when i build the project with
Runtime Library => Multi-threaded DLL (/MD)
then i get these errors and warning:
Error 4 error LNK1169: one or more multiply defined symbols found
Error 1 error LNK2005: __invoke_watson already defined in MSVCRT.lib(MSVCR90.dll)
Error 2 error LNK2005: __strdup already defined in LIBCMT.lib(strdup.obj)
Warning 3 warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
and when build with
Runtime Library => Multi-threaded (/MT)
Error 54 error LNK1169: one or more multiply defined symbols found
Error 44 error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info##AAE#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
Error 45 error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info##AAEAAV0#ABV0##Z) already defined in LIBCMT.lib(typinfo.obj)
Error 11 error LNK2005: ___iob_func already defined in LIBCMT.lib(_file.obj)
Error 39 error LNK2005: __beginthreadex already defined in LIBCMT.lib(threadex.obj)
Error 47 error LNK2005: __close already defined in LIBCMT.lib(close.obj)
...
Chilkat offers both "Multithread DLL" and "Multithread" (i.e. static) libs. Make sure you link with ChilkatRelDll.lib instead of ChilkatRel.lib
Chilkat offers both "Multithread DLL" and "Multithread" (i.e. static) libs. Make sure you link with ChilkatRelDll.lib instead of ChilkatRel.lib
This error occurred due to linking ChilkatRel.lib in Multithread DLL Runtime Project which occurs same lib file more than one time, which occurred multiple definitions of a function. these symbols are present in libcmt.lib
You can resolve this problem by using Runtime Library as Multi-threaded DLL (/MD) and
Adding "libcmt.lib" to the "Ignore Specific Library" field doesn't get me past this problem.
I'm working on developing a Windows CLR form to create GUI interaction for some code I've been handling as a console program.
When I include the header in the console portion of the code, both of my headers play fine together, but when I try to include them in the form, they result in the following:
librarytest.obj: error LNK2005: _SeqWait already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _KillDLL already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _SetSinFreq2 already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _ConnectDirect already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _GetDevice already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _SetSinFreq_Fine2 already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _Connect already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _TacOnTimeForTAction already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _SetSinFreq1 already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _GetLastEAIError already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _SetGain already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _Disconnect already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _ReadFWVer already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _SetSinFreq_Fine1 already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _SetSigSrc already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _ClosePort already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _ShowDebugInfo already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _OpenPort already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _DiscoverDevices already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _TacOnTime already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _PulseOnTime already defined in Gesture_Elicitor.obj
librarytest.obj : error LNK2005: _tactorhandle already defined in Gesture_Elicitor.obj
....
The interesting problem is that one of my headers ("wiimote.h", from the WiiYourself project) works fine if its the only one included. The problem lies with "tactor_cHeader.h", which connects to its .dll . The abbreviated code in question is as follows:
#ifndef TACTOR_H_
#define TACTOR_H_
using namespace std;
#include <windows.h>
...
typedef int (*ConnectDirectPtr)(char*name, int type);
typedef int (*TacOnTimePtr)(int cidx, int board, int tacNum, int durMilli, bool returnifprocessing);
typedef int (*SetFreqPtr)(int cidx, int board, int freq, bool returnifprocessing);
typedef int (*KillDLLptr)();
typedef int (*SeqWaitPtr)(int cidx, int board, int waitTime, bool returnifprocessing);
...
ConnectDirectPtr ConnectDirect;
TacOnTimePtr TacOnTimeForTaction;
SetFreqPtr SetSinFreq1;
SetFreqPtr SetSinFreq2;
KillDLLptr KillDLL;
SeqWaitPtr SeqWait;
...
HINSTANCE tactorhandle = NULL;
inline int InitTactorDLL()
{
tactorhandle = LoadLibrary("Tactor_DLL.dll");
if (tactorhandle == 0)
return -1;
SeqWait = (SeqWaitPtr)GetProcAddress(tactorhandle, "SeqWait");
ConnectDirect = (ConnectDirectPtr)GetProcAddress(tactorhandle, "ConnectDirect");
TacOnTime = (TacOnTimePtr)GetProcAddress(tactorhandle, "TacOnTime");
SetSinFreq1 = (SetFreqPtr)GetProcAddress(tactorhandle, "SetSinFreq1");
SetSinFreq2 = (SetFreqPtr)GetProcAddress(tactorhandle, "SetSinFreq2");
KillDLL = (KillDLLptr)GetProcAddress(tactorhandle, "KillDLL");
}
#endif
So what is it about this header that isn't playing nice with my form?
Sorry for the late reply.
The problem is simple, you have variable definitions inside your header file. Generally, a header file should only contain declarations. Check [SO]: What is the difference between a definition and a declaration? to see the difference between the two.
To fix, you should move these:
ConnectDirectPtr ConnectDirect;
TacOnTimePtr TacOnTimeForTaction;
SetFreqPtr SetSinFreq1;
SetFreqPtr SetSinFreq2;
KillDLLptr KillDLL;
SeqWaitPtr SeqWait;
//...
HINSTANCE tactorhandle = NULL;
into the .c source file that really needs them, or make them extern ([MS.Docs]: extern (C++)).
Background
There are 3 phases when building C (C++) code into Portable Executable code (here I'm referring to .exe and .dll files). For more info, check [MS.Docs]: Peering Inside the PE: A Tour of the Win32 Portable Executable File Format:
1. Preprocess
Done by the preprocessor (cl.exe: [MS.Docs]:
Compiler Options Listed Alphabetically) which is also the compiler (check next phase); this is by default a silent phase (you can see its output by specifying /E, /EP or /P flags)
For every source (.c, .cpp, .cxx, c++, ...) file, it handles all the preprocessing directives ([MS.Docs]: Preprocessor Directives) (e.g.: #define, #if, #include, ...); the result is still a .c (.cpp, ...) file (different than the original, usually, significantly larger) also called compilation unit or translation unit
When an #include directive is encountered, the line that contains the directive (there's only one file included per line of code) is simply replaced by the contents of the (.h or even .c (.cpp, ...)) file included. Note that this is done recursively (if the file included itself contains #include directives they are expanded as well, and so on). The original source file is much smaller than the preprocessed one, which is one of the preprocessor existence reasons
2. Compile
Done by the compiler (check previous phase)
Every translation unit generated at previous phase is converted from C (C++) code (human readable) to machine code (CPU "readable") or COFF format ([MS.Docs]: PE Format). This is the object (.obj) file (its content is gibberish - at least at 1st sight), that can be seen in the VC project's intermediary directory
Note that for each source file included in the project, after this phase there will be a corresponding .obj file
3. Link
Done by the linker (link.exe: [MS.Docs]: Linker Options)
All the object files from the previous phase are merged together (with a bunch of .lib files whose content is similar to .obj file's, but those can only be used indirectly - when building an App) plus some additional operations (e.g. adding the PE sections and headers, relocating some of the code, removing unused code, ...) into the final artifact of the project (the exe or the dll)
Note: this is Win specific, for Nix the phases are (almost) the same, tools differ.
What happens in your code:
The file tactor.h (I'm assuming this is its name, based on the include guard at the beginning) contains a bunch of variable definitions; I'm taking HINSTANCE tactorhandle as an example
Files librarytest.c and Gesture_Elicitor.c (got their names from the linker error) both #include (directly or indirectly) tactor.h
At Phase #1., tactor.h will be expanded in both .c files (independently). So, both translation units will have tactorhandle variable
At Phase #2., the 2 translation units from previous step are compiled and turned into object files, since their code is syntactically correct
At Phase #3., when combining the 2 object files, the linker sees that tactorhandle is present in both of them, and then spits the errors above
Notes:
You can also specify /FORCE:MULTIPLE option to the linker (by adding it to the VC Project Properties -> Linker -> Command Line -> Additional Options), but bear in mind that this might yield unexpected results (it doesn't even work for /clr compiled projects)
Since the project involves .dlls and functions import / export, you could also check [SO]: Linker error when calling a C function from C++ code in different VS2010 project (#CristiFati's answer), for errors that might appear when using this .dll
I am trying to compile my c++ project in visual studio 2010, that has been running fine in debug mode for the past several months. I am finished developing it, so I would like to create an exe to release.
The issue is that I am receiving a bunch of compiler errors when I switch it to release mode that I am not sure how to debug.
Any help would be appreciated:
1>main.obj : error LNK2005: "int __cdecl initKinect(void)" (?initKinect##YAHXZ) already defined in gui.obj
1>main.obj : error LNK2005: _main already defined in gui.obj
1>Kinect.lib(Kinect-win32.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in algorithm.obj
1>Kinect.lib(Kinect-win32.obj) : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification
1>Kinect.lib(Kinect-Driver.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in algorithm.obj
1>Kinect.lib(Kinect-FrameInput.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in algorithm.obj
1>libcpmtd.lib(stdthrow.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in algorithm.obj
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __heap_alloc already defined in LIBCMT.lib(malloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __recalloc already defined in LIBCMT.lib(recalloc.obj)
1>LIBCMTD.lib(dbgheap.obj) : error LNK2005: __msize already defined in LIBCMT.lib(msize.obj)
1>LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in LIBCMT.lib(dbghook.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype_l already defined in LIBCMT.lib(isctype.obj)
1>LIBCMTD.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj)
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Users\Tom\Documents\Kinect\repository\KinectTracker\Release\KinectTracker.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This looks to me like you are linking two sets of libraries (besides possible other problems). Libcmtd is multithreaded-debug version of libc, and libcmt is release version of same thing.
I am attempting to build Chromium for windows (using Visual Studio 2008 SP1) and it fails with about 37 errors. Here's a selection:
Error 1 error LNK2005: "wchar_t const * const switches::kProcessChannelID" (?kProcessChannelID#switches##3QB_WB) already defined in ipc.lib(ipc_switches.obj) common.lib chrome_dll
Error 2 error LNK2005: "wchar_t const * const switches::kDebugChildren" (?kDebugChildren#switches##3QB_WB) already defined in ipc.lib(ipc_switches.obj) common.lib chrome_dll
Error 3 error LNK2005: "wchar_t const * const switches::kIPCUseFIFO" (?kIPCUseFIFO#switches##3QB_WB) already defined in ipc.lib(ipc_switches.obj) common.lib chrome_dll
Error 4 fatal error LNK1169: one or more multiply defined symbols found C:\Users\RCIX\src\chrome\Debug\chrome.dll 1 chrome_dll
Those errors are the only type of errors that how up but they pop up in about half a dozen projects. What did i do wrong?
It means that the symbols are defined in two places; ipc.lib (via ipc_switches.obj) and common.lib. I am not familiar with Chromium at all, but I would guess that common.lib incorporates ipc.lib and the chrome_dll project is trying to link to both libs. Try removing ipc.lib from the linker inputs.