Static linking with Boost and ncurses

2019-07-20 18:05发布

I am in the process of making a basic role-playing game. I want to include the Boost libraries statically so that the people who run my game do not need to have them. I researched and looked-up that all you have to do is add -static to the command-line compile, so my command is like this:

$ g++ -static -o karthas *.o -lncurses -lmenu -lboost_system -lboost_filesystem

But apparently the -static is affecting ncurses. I am getting a whole bunch of errors, most of which are undefined reference to 'SP'.

Is it possible to just do a static link to Boost and not ncurses? How would I go about doing that?

2条回答
虎瘦雄心在
2楼-- · 2019-07-20 18:54

You can choose which libraries will be linked statically and which will be linked dynamically by putting either -Wl,-static or -Wl,-Bdynamic before their name.

For example, with:

g++  -o karthas *.o -Wl,-static -lmenu -lboost_system -lboost_filesystem -Wl,-Bdynamic -lncurses 

The menu, boost_system and boost_filesystem libraries will be linked statically and ncurses dynamically.

(But you can also distribute the boost dlls with your executable, and not link anything statically).

查看更多
萌系小妹纸
3楼-- · 2019-07-20 19:01

But looking at this, it seems that you are not alone, either that, or I found your issue. But this, might have your solution, either way, good luck. Btw, some boost libraries are little more than inline functions that are imported when included in the file.

查看更多
登录 后发表回答