Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

A easy build way for MS Visual Studio user #1690

Closed
alawn-wang opened this issue Sep 12, 2023 · 7 comments
Closed

A easy build way for MS Visual Studio user #1690

alawn-wang opened this issue Sep 12, 2023 · 7 comments
Labels

Comments

@alawn-wang
Copy link
Contributor

alawn-wang commented Sep 12, 2023

My project use Windows VS compile, but I can't run it successful, I have try all ways below two issues, it's no useful. No matter use static lib or dynamic lib, complier gives me link error.
#1212 #550

But I have find another way, it can help me compile project easily, use vs generator in cmake.
Build Steps:
mkdir build
cd build
cmake -G "Visual Studio 17 2022" -A x64 //just for vs2022
cmake --build . --config Release
MoreVisual Studio version details read this https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#id14

Compile in project:
Add NNG_STATIC_LIB in Preprocessor #this is important, it's not so usual for vs user
Add include file path
Add lib file and file path in linker

Then can run project easily. I have tried use build way in project index and compile, it no use. but I use cmake visual studio generator. I successful.

I also notice that you seems do not use visual studio, I can give more details about how to compile

@gdamore
Copy link
Contributor

gdamore commented Sep 14, 2023

Indeed I don't use Visual Studio.

The requirement for NNG_STATIC_LIB depends on whether you want to use static libraries and linking or not. If you want to use dynamic linking on Windows its a bit more complicated.

You have to build with NNG_SHARED_LIB when building the library itself (which should be done automatically), and then don't build with either NNG_STATIC_LIB or NNG_SHARED_LIB when you are building an application that should use the library.

I should probably just look into building an import lib file for Windows.

@cloudfirst
Copy link

I try the below commands

  • mkdir build
  • cd build
  • cmake -G "Visual Studio 17 2022" -A x64 ..
  • cmake --build . --config Release

then I get the result in build\Release directory as below

build\Release

Mode LastWriteTime Length Name


-a---- 2023/9/18 17:51 1621412 nng.lib
-a---- 2023/9/18 17:51 1655696 nng_testing.lib

so I wonder whether default output is static lib or dynamic lib ?

by the way, I hope to use nng in C# project.

@alawn-wang
Copy link
Contributor Author

I try the below commands

  • mkdir build
  • cd build
  • cmake -G "Visual Studio 17 2022" -A x64 ..
  • cmake --build . --config Release

then I get the result in build\Release directory as below

build\Release

Mode LastWriteTime Length Name

-a---- 2023/9/18 17:51 1621412 nng.lib -a---- 2023/9/18 17:51 1655696 nng_testing.lib

so I wonder whether default output is static lib or dynamic lib ?

by the way, I hope to use nng in C# project.

default output is a static lib, if you want to get a dynamic lib, maybe you should use -DBUILD_SHARED_LIBS=ON, more details in #1212 , But I haven't try this way

@alawn-wang
Copy link
Contributor Author

Indeed I don't use Visual Studio.

The requirement for NNG_STATIC_LIB depends on whether you want to use static libraries and linking or not. If you want to use dynamic linking on Windows its a bit more complicated.

You have to build with NNG_SHARED_LIB when building the library itself (which should be done automatically), and then don't build with either NNG_STATIC_LIB or NNG_SHARED_LIB when you are building an application that should use the library.

I should probably just look into building an import lib file for Windows.

I know what you want to say, But if I do as index said, and then no matter the static lib or dynamic lib can't be linked correctly in Visual Studio. it need not to be built again, it just do link ,like this, 'gcc -L libpath -llibnng -I header_path'

@gdamore
Copy link
Contributor

gdamore commented Nov 26, 2023

The situation with static vs. dynamic libs on Windows is a bit annoying, for certain. CMake has not done much to make this easier.

One possible problem is that the Visual Studio recipes might be getting this wrong. If you're building NNG itself, you should use NNG_SHARED_LIB, and then when you build calling library you don't need to do either.

If you're using static libaries, just put NNG_STATIC_LIB in your cmake configuration.

@gdamore
Copy link
Contributor

gdamore commented Nov 26, 2023

Btw, we always build a static library for the test suites.

@uusdnfdsfhnttyh
Copy link

use vcpkg

@nanomsg nanomsg locked and limited conversation to collaborators Feb 24, 2024
@gdamore gdamore converted this issue into discussion #1780 Feb 24, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

4 participants