This may be a Visual Studio question more than anything else...
I'm trying to build a 0MQ C++ example using VS10 and ZeroMQ 2.2.0.
I downloaded the windows sources and tried to follow these instructions in order to build 0MQ statically. Specifically:
Switched to Release
For all 7 projects in the solution:
set General\Configuration Type to Static library (.lib)
set C/C++\Code Generation\Runtime Library to Multi-threaded (/MT)
added ZMQ_STATIC to C/C++\Preprocessor\Preprocessor Definitions
Updated zmq.h and zmq_utils.h so that if _MSC_VER and ZMQ_STATIC are defined then DLL_EXPORT will also be defined
At this point 0MQ seems to build well.
Created an empty console project:
switched to Release
added a single cpp file with the example linked above
changed random to rand, srandom to srand and snprintf to _snprintf
set C/C++\Code Generation\Runtime Library to Multi-threaded (/MT)
added ...\zeromq-2.2.0\include folder to C/C++\General\Additional Include Directories
added ...\zeromq-2.2.0\builds\msvc\Release\*.lib to Linker\Input\Additional Dependencies
However I still receive the following linking errors:
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_bind
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_close
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_errno
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_init
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_data
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_strerror
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_socket
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_init_size
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_term
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_msg_close
1>zmqexp.obj : error LNK2001: unresolved external symbol __imp__zmq_send
What have I missed?
You should add ZMQ_STATIC to C/C++\Preprocessor\Preprocessor Definitions in your "empty console project" too. Otherwise, when you compile your application, ZMQ_EXPORT in zmq.h is defined as __declspec(dllimport), and as a result, MSVC looks for __imp__zmq_* symbols instead of zmq_*
I had similar errors - not when trying to statically link, but just trying to create a ZMQ project and link the .lib 'stubs' for the dll.
In my case it was because I was trying to link the 64-bit libraries into a 32-bit project. I had downloaded the wrong version. When I got the right ones, ie x86 instead of x64, it worked.
Is the static linking very important to you? If not, you can try out the second answer by elnino_9 here. Elaborating elnino_9's answer:
Download the sources and unzip to some local folder (say C:\dev\zeromq).
Go to C:\dev\zeromq-2.2.0\builds\msvc and open the msvc.sln solution. MS2010 will upgrade from a VS2008 to a VS2010 project
Build all of the projects.
The build should generate the two following files:
C:\dev\zeromq\lib\libzmq.lib - this is what you will need to reference in your project's linker options
C:\dev\zeromq_boaz\builds\msvc\Release\libzmq.dll - this you will need to copy to the same folder as your project's executable in order to run it (if your build was configured to 'Debug', the path would be C:\dev\zeromq\builds\msvc\ Debug \libzmq.dll)
Create your solution and project. Do the following:
In the Solution Explorer, right-click on you project, and select 'Properties' (at the very bottom).
Navigate to 'C/C++ --> General --> Additional Include Directories' and add C:\dev\zeromq\include. This will reference 0MQ's header files.
Navigate to 'Linker --> Input --> Additional Dependencies' and add the full path to the 'libzmq.dll' file from the previous step.
Build your project - this should go without errors now.
Copy 'libzmq.dll' to the same folder as your executable - your project should now run.
Some comments:
I am not sure why you need to reference the 'libzmq.lib' file. It is not needed by the executable (you can delete it, and it will still run, as the necessary logic resides in the dll). Can someone explain this?
Notice one caveat in the example for Windows users - the second binding statement (publisher.bind("ipc://weather.ipc");) will cause an exception. As explained here (though in fine-print), the Inter-Process Transport is not supported on Windows.
EDIT
I think the answer to my first comment can be found in MSDN:
"When the source code for the calling executable is compiled or assembled, the DLL function call generates an external function reference in the object code. To resolve this external reference, the application must link with the import library (.lib file) provided by the maker of the DLL."
Related
I have project where I want to import library. When I do that (import .lib files from library) and than call any function from library I get following errors:
"C:\Uz\myproj.vcxproj" (default target) (1) ->(Link target) ->
aziotsharedutil.lib(consolelogger.obj) : error LNK2005: printf already defined in msvcrtd.lib(MSVCR120D.dll) [C:\Uz\myproj.vcxproj]
aziotsharedutil.lib(socketio_win32.obj) : error LNK2005: _vsnprintf_l already defined in msvcrtd.lib(MSVCR120D.dll) [C:\Uz\myproj.vcxproj]
uamqp.lib(amqpvalue_to_string.obj) : error LNK2005: _vsnprintf_l already defined in msvcrtd.lib(MSVCR120D.dll) [C:\Uz\myproj.vcxproj]
C:\Dz\myproj.vcxproj\myproj.dll : fatal error LNK1169: one or more multiply defined symbols found [C:\Uz\myproj.vcxproj]
0 Warning(s)
4 Error(s)
Does anyone know how can i fix this?
I have following libraries imported in my project:
msvcprtd.lib
msvcrtd.lib
kernel32.lib
ole32.lib
aziotsharedutil.lib //imported Library .lib file
uamqp.lib //imported Library .lib file
eventhub_client.lib //imported Library .lib file
Advapi32.lib
Crypt32.lib
Ws2_32.lib
Secur32.lib
ucrt.lib
vcruntime.lib
Note 1
All 3 projects that are built as Static Link Library .lib, have same settings Multi-threaded Debug DLL (/MDd), same as my project.
Thanks!
Compiled with same version of compiler and that solved my problem!
I made a new project for unittesting with googleTest. I then added a source file from another project to test it. I then got severeal linker errors:
nafxcwd.lib(timecore.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(apphelp.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(filelist.obj) : error LNK2001: unresolved external symbol __mbctype
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argv
nafxcwd.lib(appcore.obj) : error LNK2001: unresolved external symbol ___argc
The key options in my projects are:
Testproject:
Runtime Library: Multithreaded Debug DLL (necessary for googleTest)
Use of MFC: Shared DLL
productive project: (this should actually not matter)
Runtime Library: Multithreaded Debug DLL
Use of MFC: Use MFC in a static library
Even if I copy all the options and files from the productive project with MFC as shared DLL these messages get thrown.
The file, that was imported to the testproject had the "stdafx.h"-include that was resolved to the productive projects one.
There,
#include <afxwin.h>
was included. Checking that one turned out, that for shared MFC-DLL, you need to
#define _AFXDLL
in your project / before the afxwin-include. Otherwise you get these errors.
I have pangoft2.vcproj. Once I have set the include directories etc., it compiles successfully.
Now, in a new .sln (where I have a pango.vcproj), I add this pangoft2.vcproj. Now, when I compile the program, it gives 474 errors.
I have copied a few lines here:
Error 20 error LNK2001: unresolved external symbol __imp_g_utf8_skip thai-shaper.obj
Error 47 error LNK2001: unresolved external symbol g_utf8_get_char thai-shaper.obj
Error 121 error LNK2001: unresolved external symbol pango_glyph_string_set_size thai-shaper.obj
Error 130 error LNK2001: unresolved external symbol pango_font_get_glyph_extents thai-shaper.obj
I must tell you that I have included the required libraries (pango-1.0.lib and glib-2.0.lib) in the project.
Can you tell me the possible reason of this error and how to over come it ?
Thanks in advance.
Resolved the error.
The project was in the Debug x64 mode, when I should have used debug win32 mode.
I'm trying to get accustomed to both MFC development and Visual Studio so I have installed Visual Studio 2012 RC and have created a simple MFC Application. Currently the application is little more than the MFC Wizard generated for me.
I decided I wanted to incorporate an XML Library so I found this one on github. I download the ZIP file with the source code, unzip it and then in Visual Studio I goto the solution explorer, choose my solution, right click and choose "Add" > "Existing Project". I select the project file for the source code and it appears in my Solution Explorer tree.
I test the code compiles and it does. However I'm not quite sure how to use it from my current solution.
I try to use this code in my doc:
#include "../../TinyXML2/leethomason-tinyxml2-a3efec0/tinyxml2.h"
<...snip...>
BOOL LoadDocumentFromXML(const CString& filename) {
CT2CA pszConvertedAnsiString (filename);
std::string s(pszConvertedAnsiString);
tinyxml2::XMLDocument doc(true);
if (tinyxml2::XML_NO_ERROR != doc.LoadFile(s.c_str())) {
return FALSE;
}
return TRUE;
}
However I get this linker error when I try to build the project:
------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
GraphAppDoc.cpp
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: __thiscall tinyxml2::XMLDocument::XMLDocument(bool)" (??0XMLDocument#tinyxml2##QAE#_N#Z) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML##YAHABV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z)
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall tinyxml2::XMLDocument::~XMLDocument(void)" (??1XMLDocument#tinyxml2##UAE#XZ) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML##YAHABV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z)
GraphAppDoc.obj : error LNK2019: unresolved external symbol "public: int __thiscall tinyxml2::XMLDocument::LoadFile(char const *)" (?LoadFile#XMLDocument#tinyxml2##QAEHPBD#Z) referenced in function "int __cdecl LoadDocumentFromXML(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > const &)" (?LoadDocumentFromXML##YAHABV?$CStringT#_WV?$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z)
C:\Users\Phill\Documents\Visual Studio 2012\Projects\GraphApp\Debug\GraphApp.exe : fatal error LNK1120: 3 unresolved externals
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
In the solution explorer I select my MFC application project, right click and choose "Dependencies". I make sure the MFC app is set to be dependent on tinyxml project and I ensure the "Build Order" is correct (tinyxml first). I also goto into "References..." and add tinyxml there too. I even add the debug directory of tinyxml to my MFC app's include path in project properties as well. What am I missing please?
Ok it turns out I didn't read the documentation fully. Reading the XML attached the project here states:
It is one header and one cpp file. Simply add these to your project
and off you go.
So I did this. Then I got some compiler warnings:
------ Build started: Project: GraphApp, Configuration: Debug Win32 ------
tinyxml2.cpp
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(24): warning C4627: '#include "tinyxml2.h"': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(26): warning C4627: '#include <cstdio>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(27): warning C4627: '#include <cstdlib>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(28): warning C4627: '#include <new>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(29): warning C4627: '#include <cstddef>': skipped when looking for precompiled header use
Add directive to 'stdafx.h' or rebuild precompiled header
c:\users\phill\documents\visual studio 2012\projects\graphapp\graphapp\tinyxml2.cpp(1834): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So then I selected "tinyxml2.cpp" in the solutions explorer, right clicked, went to properties. In properties under "C++" I went to "Precompiled Headers" and changed the option that read:
Precompiled Header: Use
to
Precompiled Header: Not using precompiled headers
Then it magically worked!
There is one idl file defined in microsoft sdk which is not available in VS2005. I am using some of the interfaces from that IDL.
Now this works fine on VS 2010 . I want to make it compile on VS2005.
I copied the header file to my project directory. But it is giving me compilation error.
When I looked into header file , the class id is defined in it as
EXTERN_C const CLSID CLSID_Xyz.
Now it is defined as extern so it means it should be declared somewhere else in code.
So my question is just including .h file is sufficient or do I need to also include _i.c file.
Any suggestions
Once you examine that _i.c file you'll see the indeed the CLSID constants are defined there. So yes, you need to incorporate that .c file into you program - either by #including it into a .c or .cpp file or just by adding it to your project so that it compiles separately and then links into the final binary.