Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo application will not link demo application under windows, with nng.lib built as static library #1639

Open
rheslar123 opened this issue Jan 26, 2023 · 3 comments

Comments

@rheslar123
Copy link

NNG / Nanomsg compilation under windows

Created by Robert Heslar,
with a template
Just a moment ago3 min read
Analytics
this is instructions i have used to build the NNG library from sources

visual studio 2017 and above is required for these steps

📘 Instructions

clone the repo: GitHub - nanomsg/nng: nanomsg-next-generation -- light-weight brokerless messaging

open a visual studio command prompt, and navigate to the build directory

run cmake .., from the command line, this will create a visual studio solution named nng.sln

open the nng.sln, in visual studio

in visual studio, rebuild the solution, we now have a nng.lib file, for use with a NNG / Nanomsg Application

Highlight important information in a panel like this one. To edit this panel's color or style, select one of the options in the menu.

📋 Related articles
this shows the instructions used to build the NNG asyc application demo, found in the NNG demos folder

create the folder path as below, so cmake can find the library and header files for the NNG asyc application demo:

copy the nng includes into the include path above, the include directory in the NNG asyc application demo path:

copy the nng.lib file from the nng/build/Debug directory(from steps in the above article), to the NNG asyc application lib directory

for this NNG application, have this CMakelist.text file:

CMakeLists.txt
26 Jan 2023, 10:09 AM
6) open a visual studio command prompt, and navigate to the NNG asyc application demo build directory

  1. navigate to the NNG asyc application demo build directory path

8 run cmake .., form the NNG asyc application demo build directory

  1. a visual studio solution will be created with the name: nng-asyncdemo.sln

  2. open the nng-asyncdemo.sln in visual studio

  3. run rebuild all, in the nng-asyncdemo solution, in visual studio

problems: (added nng.lib from steps before (compiling nng source under windows)

when compiling the NNG asyc application demo visual studio we now get the following linker errors:

NNG application missing link symbols:

2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_close referenced in function server_function
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listen referenced in function server_function
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listener_create referenced in function run_server
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listener_start referenced in function run_server
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listener_get_addr referenced in function run_server
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_strerror referenced in function fatal
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_send referenced in function server_function
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_recv referenced in function recive_function1
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_free referenced in function recive_function1
2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_surveyor0_open referenced in function server_function
CMakeLists.txt
CMakeLists.txt

@gdamore
Copy link
Contributor

gdamore commented Mar 20, 2023

Yeah, the problem here is an age old one of how Windows DLLs work. There are probably ways we could make this a little less painful.

The NNG_STATIC_LIB macro should be set when building a static library, which causes the symbols to be renamed -- without that we default to using the dynamic version of symbol naming, and you get these link failures.

This is only a problem on Windows, and I'm not sure how to do a better job of making this easy for folks using DLLs or using static libraries. Right now the default favors DLL users.

@gdamore
Copy link
Contributor

gdamore commented Mar 20, 2023

If some Windows / CMake GURU comes along, maybe they can offer some wisdom to make this better.

@alawn-wang
Copy link
Contributor

alawn-wang commented Nov 30, 2023

NNG / Nanomsg compilation under windows

Created by Robert Heslar, with a template Just a moment ago3 min read Analytics this is instructions i have used to build the NNG library from sources

visual studio 2017 and above is required for these steps

📘 Instructions

clone the repo: GitHub - nanomsg/nng: nanomsg-next-generation -- light-weight brokerless messaging

open a visual studio command prompt, and navigate to the build directory

run cmake .., from the command line, this will create a visual studio solution named nng.sln

open the nng.sln, in visual studio

in visual studio, rebuild the solution, we now have a nng.lib file, for use with a NNG / Nanomsg Application

Highlight important information in a panel like this one. To edit this panel's color or style, select one of the options in the menu.

📋 Related articles this shows the instructions used to build the NNG asyc application demo, found in the NNG demos folder

create the folder path as below, so cmake can find the library and header files for the NNG asyc application demo:

copy the nng includes into the include path above, the include directory in the NNG asyc application demo path:

copy the nng.lib file from the nng/build/Debug directory(from steps in the above article), to the NNG asyc application lib directory

for this NNG application, have this CMakelist.text file:

CMakeLists.txt 26 Jan 2023, 10:09 AM 6) open a visual studio command prompt, and navigate to the NNG asyc application demo build directory

  1. navigate to the NNG asyc application demo build directory path

8 run cmake .., form the NNG asyc application demo build directory

  1. a visual studio solution will be created with the name: nng-asyncdemo.sln
  2. open the nng-asyncdemo.sln in visual studio
  3. run rebuild all, in the nng-asyncdemo solution, in visual studio

problems: (added nng.lib from steps before (compiling nng source under windows)

when compiling the NNG asyc application demo visual studio we now get the following linker errors:

NNG application missing link symbols:

2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_close referenced in function server_function 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listen referenced in function server_function 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listener_create referenced in function run_server 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listener_start referenced in function run_server 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_listener_get_addr referenced in function run_server 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_strerror referenced in function fatal 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_send referenced in function server_function 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_recv referenced in function recive_function1 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_free referenced in function recive_function1 2>survey.obj : error LNK2019: unresolved external symbol __imp_nng_surveyor0_open referenced in function server_function CMakeLists.txt CMakeLists.txt

if you want to use static lib in windows, maybe you should add a pre-compile instruction for your pre-processor such like this 'add_compile_definitions(NNG_STATIC_LIB)' in your CMakeList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants