且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在 NetBeans 的 Linux 中用 C++ 和 OpenGL (GLFW) 编译简单的源代码

更新时间:2022-06-16 02:16:34

第一件事:

这是我的来源(我没有在头文件中使用这个字符:<、>.):

this is my source (I didn't use this characters: <, > in header files.):

这是错误的,你应该这样做.您当前的 include 语句是错误的,我实际上很惊讶它是如何通过这种方式通过编译过程的.

That is wrong, and you should. Your current include statements are wrong, and I am actually surprised how it passed the compilation process this way.

您在此处看到链接器错误:

You are seeing linker errors in here:

/home/jan/NetBeansProjects/a/main.cpp:12: undefined reference to `glfwInit'
/home/jan/NetBeansProjects/a/main.cpp:16: undefined reference to `glfwCreateWindow'
/home/jan/NetBeansProjects/a/main.cpp:19: undefined reference to `glfwTerminate'
/home/jan/NetBeansProjects/a/main.cpp:22: undefined reference to `glfwMakeContextCurrent'
/home/jan/NetBeansProjects/a/main.cpp:25: undefined reference to `glewExperimental'
/home/jan/NetBeansProjects/a/main.cpp:26: undefined reference to `glewInit'

失败可能有以下几种选择:

There might be the following options for the failure:

  • 您没有链接到库(很可能)

  • You are not linking against the library (most likely)

您没有安装库(根据您的描述,不太可能)

You are not having the library installed (unlikely, based on your description)

您正在使用库中不存在的符号(再次,不太可能)

You are using symbols not present in the library (again, unlikely)

最可能的原因是您最终没有链接到库.你应该为链接器设置这个:

The most probably reason is that you are not linking against the library, eventually. You should have this set up for the linker:

-lglfw3

请注意,当您开始添加这些时,您还需要添加链中作为依赖项出现的所有内容,因此根据您的评论,这是要添加的整个链:

Note that you will also need to add everything in the chain that comes up as a dependency when you start adding these, so based on your comment this is the whole chain to add:

-L/usr/local/lib -lglfw3 -pthread -lGLEW -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11

由于您使用的是 Netbeans IDE,除非您在后台手动编辑文件,否则您将需要转到项目设置进行设置.在这里,您可以看到一个屏幕截图,它表明您有一个链接器选项卡,您可以在其中正确设置所有这些.

Since you are using the Netbeans IDE, you will need to go to the project settings to set it up unless you edit the files in the background manually. Here, you can see a screenshot which demonstrates that you have a linker tab where you can set up all this properly.