如何通过 g++ 编译独立的可执行文件
How to compile an independent executable file by g++?
我在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
问候乌尔夫
您需要
确保系统上安装了 boost 库,并且它们的路径包含在变量LD_LIBRARY_PATH
中。
例如,如果要在系统上的/usr/local/boost-1.56.0/lib64
中找到libboost_system.so
文件(或符号链接),则应运行该命令。
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/boost-1.56.0/lib64`
要准确找出所需的库,可以运行以下命令:
ldd my_binary
输出将准确告诉您需要哪些库,以及哪些库当前无法解析。
相关文章:
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 如何使字符串出现在编译的二进制可执行文件的开头?
- 程序在使用 system() 启动另一个可执行文件时停止
- 如何更改使用 CPack 安装的可执行文件的名称?
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- CMake:我们可以为一组不形成可执行文件或库的特定文件指定包含目录吗?
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 来自C++代码的独立可执行文件
- Cython:编译独立的静态可执行文件
- 有什么理由更喜欢从 IDE 中运行应用程序而不是运行独立的可执行文件?
- 如何通过 g++ 编译独立的可执行文件
- 执行一个新的完全独立的进程,该进程封装在一个可执行文件中,而不需要为独立进程将文件写入磁盘
- Qt应用程序:如何从Mac为Windows(和Mac)创建独立的可执行文件?
- 使用Visual Studio express 2013为c++代码创建独立的可执行文件
- 如何部署netbeans Qt项目的独立可执行文件
- 用c++插件为nodejs应用程序构建一个独立的可执行文件
- c++独立可执行文件
- 共享库和可执行文件与 Linux 上的静态 C 运行时链接.它们中的每一个都有像Windows这样的独立堆吗?