静态编译glfw
我正在尝试使用 GCC 4.4.3 在 Linux Mint(基于 Ubuntu 10.04)上将 glfw 编译为静态链接。
在我的项目目录中,我得到了“external/glfw”,其中包含 glfw 2.7.1 源代码。我通过运行“make x11-install”编译它,给出:
- /usr/local/include/GL/glfw.h
- /usr/local/lib/libglfw.a
- /usr/local/lib/pkgconfig/libglfw.pc
我还在 test.c 中得到了这个简单的代码:
#include <stdio.h>
#include <stdlib.h>
#include "external/glfw/include/GL/glfw.h"
int main( int argc, char const* argv[] )
{
if( !glfwInit() ){
fprintf( stderr, "glfwInit Failed\n" );
}
glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 4 );
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 1 );
glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW )){
fprintf( stderr, "glfwOpenWindow failed\n" );
glfwTerminate();
return -1;
}
return 0;
}
我正在尝试将 glfw 编译为静态链接,并使用带标志的 gcc 编译代码:
/usr/bin/gcc `pkg-config --cflags libglfw` -o test test.c \
`pkg-config --libs libglfw` -lXrandr -lX11 -lGLU -lGL -pthread -lm
并且它不会给我任何错误。但是当我尝试执行二进制文件时,它显示我无法调用 glfwOpenWindow。
有人可以帮我吗?谢谢你们的宝贵时间!
干杯!
P
编辑1:我认为问题在于链接过程而不是代码。因为如果我安装了 libglfw2 和 libglfw-dev (ubuntu 软件包),那么可执行文件运行得很好。我在这里想要的是让 glfw 静态链接,而不是依赖发行版包共享库来运行二进制文件。
编辑2根据datenwolf的建议,我尝试使用gdb进行调试。我以前从未使用过 gdb,但我经常使用 perl 调试器。不知怎的,他们有很多相似之处。我用-ggdb重新编译glfw和我的test.c。
与gdb一起流动它表明我的代码进入glfwOpenWindow(),它位于glfw源代码的“window.c”中。因为我是 gdb 新手,所以我不知道如何计算表达式或获取变量的值。基于谷歌上的快速搜索,我所知道的是“whatis”来查看日期类型。但我认为我的代码在到达“window.c”中的第484行时停止了,
if( wndconfig.glProfile &&
( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
{
// Context profiles are only defined for OpenGL version 3.2 and above
return GL_FALSE;
}
现在我不确定为什么使用静态链接glfw认为我不在OpenGL 3.2及更高版本上,而安装了libglfw2它工作得很好?
谢谢你们的帮助!尤其是大狼!
编辑3感谢大家的帮助。在 stackoverflow 和 old nabble 中的人们的帮助下,我设法写下需要对静态链接的 GLFW 和 GLEW 执行的操作,并将其放在 http://www.phacks.net/static-compile-glfw-and-glew/
I'm trying to compile glfw as static link on Linux Mint (based on Ubuntu 10.04) using GCC 4.4.3.
Inside my project directory i got "external/glfw" which contains glfw 2.7.1 source. I've compiled it by running "make x11-install" which gives:
- /usr/local/include/GL/glfw.h
- /usr/local/lib/libglfw.a
- /usr/local/lib/pkgconfig/libglfw.pc
i also got this simple code in test.c:
#include <stdio.h>
#include <stdlib.h>
#include "external/glfw/include/GL/glfw.h"
int main( int argc, char const* argv[] )
{
if( !glfwInit() ){
fprintf( stderr, "glfwInit Failed\n" );
}
glfwOpenWindowHint( GLFW_FSAA_SAMPLES, 4 );
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 1 );
glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
// Open a window and create its OpenGL context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW )){
fprintf( stderr, "glfwOpenWindow failed\n" );
glfwTerminate();
return -1;
}
return 0;
}
i'm trying to compile glfw as static link and compiled the code using gcc with flags:
/usr/bin/gcc `pkg-config --cflags libglfw` -o test test.c \
`pkg-config --libs libglfw` -lXrandr -lX11 -lGLU -lGL -pthread -lm
and it doesn't give me any error. but when i try to execute the binary it shows that i've failed to call glfwOpenWindow.
could any one help me please? thank you for your time guys!
cheers!
P
EDIT 1: I think the problem lies with the linking process and not the code. Because if i have libglfw2 and libglfw-dev installed (ubuntu packages), then the executable runs just fine. What i want here is to have glfw statically linked and not to rely on distro package share libs for the binary to run.
EDIT 2 as per datenwolf suggestion i tried to debug with gdb. i never use gdb before but i use perl debugger a lot. somehow they share a lot of similarities. i recompile glfw and my test.c with -ggdb.
flowing with gdb it shows that my code goes into glfwOpenWindow() which is in "window.c" in glfw source code. since i'm new to gdb i don't know how to evaluate expression or get the value of variables. based on quick search on google all i know is "whatis" to see the date type. but i think my code stops when it reached line 484 in "window.c"
if( wndconfig.glProfile &&
( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
{
// Context profiles are only defined for OpenGL version 3.2 and above
return GL_FALSE;
}
now i'm not sure how come using static link glfw thinks i'm not on OpenGL 3.2 and above, while having libglfw2 installed it works just fine?
thanks for your help guys! especially datenwolf!
EDIT 3 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/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么您的错误是对
glfwOpenWindow
的调用失败?在调用main()
之前,没有未解析的符号
或未找到共享对象
消息?然后您成功静态链接到 GLFW。我认为您的问题在于传递给
glfwOpenWindow
的参数:因此您请求每个通道的红色、绿色或蓝色位为零,但深度位为 32。我怀疑你的系统支持这一点。我会尝试
大多数系统都很好地支持这一点。
So your error is that the call to
glfwOpenWindow
failed? Nounresolved symbol
orshared object not found
messages before evenmain()
gets called? Then you successfully linked against GLFW statically.I think your problem lies in the parameters you pass to
glfwOpenWindow
:So you're requesting zero red, green or blue bits per channel, but 32 depth bits. I doubt your system supports that. I'd try
that's what most systems support well.
您的示例程序请求 OpenGL 3.1 和上下文配置文件。配置文件仅针对 OpenGL 3.2 及更高版本定义,这很可能是
glfwOpenWindow
在这种情况下失败的原因。要解决此问题,请请求高于或等于 3.2 的版本,或删除对上下文配置文件的请求。有关使用 GLX 创建现代 OpenGL 上下文的更多信息(GLFW 的这一部分是一个薄层),请参阅
http://www.opengl.org/registry/specs/ARB/glx_create_context.txt 。
Your example program requests OpenGL 3.1 and a context profile. Profiles are only defined for OpenGL 3.2 and above, which is most likely why
glfwOpenWindow
fails in this case. To fix this, either request a version above or equal to 3.2, or remove the request for a context profile.For more information about modern OpenGL context creation with GLX, upon which this part of GLFW is a thin layer, see
http://www.opengl.org/registry/specs/ARB/glx_create_context.txt .