【发布时间】:2016-05-27 09:28:02
【问题描述】:
我在我的 OpenSUSE 上开发了一个 c++ 软件,我喜欢在另一个 OpenSUSE 系统上进行测试。
我在另一个系统上复制了可执行文件,但是当我启动它时,我收到一个错误:
“加载共享库时出错:libboost_system.so.1.61.0: 无法打开共享对象文件:没有这样的文件或目录”
如何编译没有依赖的独立可执行文件?
Eclipse 会这样做:
17:24:41 **** Incremental Build of configuration Debug for project boostServer ****
make all
Building file: ../src/boostCom.cpp
Invoking: Cross G++ Compiler
g++ -I/opt/boost -I/usr/local/lib -O0 -g3 -Wall -c -fmessage-length=0 -isystem /opt/boost -MMD -MP -MF"src/boostCom.d" -MT"src/boostCom.o" -o "src/boostCom.o" "../src/boostCom.cpp"
Finished building: ../src/boostCom.cpp
Building file: ../src/main.cpp
Invoking: Cross G++ Compiler
g++ -I/opt/boost -I/usr/local/lib -O0 -g3 -Wall -c -fmessage-length=0 -isystem /opt/boost -MMD -MP -MF"src/main.d" -MT"src/main.o" -o "src/main.o" "../src/main.cpp"
Finished building: ../src/main.cpp
Building target: boostServer
Invoking: Cross G++ Linker
g++ -L/usr/local/lib -o "boostServer" ./src/boostCom.o ./src/boostServer.o ./src/main.o -lboost_system -lboost_serialization -lboost_thread -lboost_date_time -lpthread
Finished building target: boostServer
问候乌尔夫
【问题讨论】:
-
你可以使用静态链接。
-
@Ulf 在链接 g++ 中使用
-static。 (即您列表中的最后一个),那么,如果有静态库,它将更喜欢它们共享。
标签: c++ g++ executable libraries