Вопрос по visual-studio – ссылка на статическую библиотеку 0MQ в VS

12

Это может быть вопрос Visual Studio больше всего на свете ...
Я пытаюсь построитьпример 0MQ C ++ используя VS10 и ZeroMQ 2.2.0.
Я скачалисточники Windows и пытался следоватьэти инструкции для того, чтобы построить 0MQ статически. В частности:

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

На данный момент 0MQ, кажется, строит хорошо.

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

Однако я все еще получаю следующие ошибки компоновки:

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

Что я пропустил?

Ваш Ответ

3   ответа
2

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.

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

:

"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."

В частности, речь идет о статической компоновке, поэтому не следует использовать DLL.
4

17

ZMQ_STATICC/C++\Preprocessor\Preprocessor DefinitionsZMQ_EXPORTzmq.h__declspec(dllimport)__imp__zmq_*zmq_*

Error: User Rate Limit Exceeded

Похожие вопросы