[英]How to compile an independent executable file by g++?
I devellop a piece of c++ software on my OpenSUSE, which I like to test on another OpenSUSE system. 我在自己的OpenSUSE上开发了一个c ++软件,我想在另一个OpenSUSE系统上进行测试。
I copied the executable file on the other system, but when I am starting it I receive an error: 我在其他系统上复制了可执行文件,但是在启动它时收到错误消息:
"error while loading shared libraries: libboost_system.so.1.61.0: cannot open shared object file: No such file or directory"
“加载共享库时出错:libboost_system.so.1.61.0:无法打开共享库文件:没有这样的文件或目录”
How can I compile an independent executable without dependencies? 如何编译没有依赖项的独立可执行文件?
Eclipse does this: 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
Greets Ulf 迎接乌尔夫
You need to make sure you have the boost libraries installed on your system, and that the path to them is included in you LD_LIBRARY_PATH
variable. 您需要确保已在系统上安装了Boost库,并且
LD_LIBRARY_PATH
变量中包含了它们的路径。
For example, if the libboost_system.so
file (or symlink) is to be found at /usr/local/boost-1.56.0/lib64
on your system, then you would run the command. 例如,如果要在
/usr/local/boost-1.56.0/lib64
上的/usr/local/boost-1.56.0/lib64
找到libboost_system.so
文件(或symlink),则应运行命令。
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/boost-1.56.0/lib64`
To find out exactly which libraries you need, you can run the command: 要确切找出所需的库,可以运行以下命令:
ldd my_binary
The output will tell you exactly which libraries are required, and which of those can't currently be resolved. 输出将准确告诉您需要哪些库,以及哪些库当前无法解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.