静态构建问题Linux上的glfw [英] static build glew & glfw on linux
问题描述
在我的项目目录中,我有:
In my project directory, i have:
- ./external/glew,已从源代码编译(运行make)
- ./external/glfw,也具有从源代码编译的glfw(运行make x11)
在我的.c源代码中:
#include <stdio.h>
#include <stdlib.h>
#include "external/glew/include/GL/glew.h"
#include "external/glfw/include/GL/glfw.h"
我尝试使用GCC进行编译:
i tried to compile using GCC:
gcc test1.c -o test1 -DGLEW_STATIC -L./external/glew/lib -lGLEW -lGLU -lGL \
-L./external/glfw/lib/x11 -lglfw
./external/glew/lib是libGLEW.a所在的位置,./external/glfw/lib/x11是libglfw.a所在的位置.
./external/glew/lib is where the libGLEW.a is and ./external/glfw/lib/x11 is where the libglfw.a is.
并且它编译没有错误.但是然后我尝试运行./test1它给了我:
and it compiles without error. but then i try to run ./test1 it gives me:
./test1: error while loading shared libraries: libGLEW.so.1.6: cannot
open shared object file: No such file or directory
我该如何编译glamp&静态地glfw?
how do i compile glew & glfw statically?
编辑1 :感谢您的帮助.在人们对stackoverflow和旧的nash进行了一些帮助之后,我设法写下了静态链接GLFW和GLEW所需要做的事情,并将其放在
EDIT 1 Thanks for the help guys. After some help from people in stackoverflow and old nabble I manage to write it down what needs to be done to statically linked GLFW and GLEW and put it on http://www.phacks.net/static-compile-glfw-and-glew/
推荐答案
静态库未与-l链接,而是仅添加到链接器源文件中.但是,请仔细检查您是否真的要静态链接这些链接.这里的问题是,* nix系统上的动态链接器默认情况下将仅查看系统库目录和LD_LIBARY_PATH环境变量中指定的路径.
Static libraries are not linked with -l… but just added to the linker source files. However please double check you really want to link those statically. The problem you have here is that the dynamic linker on *nix systems will by default only look into the system library directories and the path specified in the LD_LIBARY_PATH environment variable.
但是,也可以向库所在的可执行文件中添加相对链接器路径(--rpath
链接器选项).这样,您可以将库独立于系统可执行文件放在相对于可执行文件的目录中.如果这样做,还应该查看 binreloc
However it is possible to add relative linker paths to the executable, where libraries are located, too (--rpath
linker option). That way you can ship the libraries in a directory relative to your executable, independently from the system libraries. If you do this, you also should look into binreloc
这篇关于静态构建问题Linux上的glfw的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!