C++ 编译GLFW代码时参数无效?
源代码:C++ 编译GLFW代码时参数无效?,c++,opengl,gcc,glfw,C++,Opengl,Gcc,Glfw,源代码: #include <glfw3.h> int main(void){ GLFWwindow* window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(640, 480, "H
#include <glfw3.h>
int main(void){
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
我尝试过的命令和错误:
g++-I Application.cpp-Wl,-BStatic-L-lglu32-lopengl32-lkernel32-luser32-lgdi32-lws2\u 32
:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
g++Application.cpp-I
:
g++Application.cpp-I-Wl,-BStatic-\libglfw3.a
:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -libglfw3.a
collect2.exe: error: ld returned 1 exit status
g++-I Application.cpp-Wl,-BStatic-L-libglfw3.a
:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -libglfw3.a
collect2.exe: error: ld returned 1 exit status
g++-I Application.cpp-Wl,-BStatic-L libglfw3.a-mwindows
:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
争论中的空格很重要 在这里: 请尝试删除多余的空间:
-Wl,-BStatic
原因是-Wl,
之后的部分是传递给链接器的参数
请参阅和之类的问题。好的,我尝试删除空格,但没有解决问题。我得到了一个错误:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: unrecognized option '-BStatic'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: use the --help option for usage information
collect2.exe: error: ld returned 1 exit status
我正在浏览gcc和链接器文档,但虽然不知道它是如何工作的,但最终还是尝试了并成功了:
g++ -I<pathHeaderFolder> Application.cpp -Wl,<pathLibraryFolder>libglfw3.a -lglu32 -lopengl32 -lkernel32 -luser32 -lgdi32 -lws2_32
g++-I Application.cpp-Wl,libglfw3.a-lglu32-lopengl32-lkernel32-luser32-lgdi32-lws2\u 32
我真的不知道它为什么起作用,但我在链接器文档中读到,如果将选项传递给链接器,则必须通过-Wl完成
另外,在链接器的库路径之前添加“-L”
-Wl,-L<pathLibraryFolder>libglfw3.a
-Wl,-Llibglfw3.a
给了我一个错误,就像我没有链接图书馆一样。我不知道为什么
但不管怎样,它成功了,所以非常感谢你的帮助!我不认为争论中的空格很重要
-Wl,-L<pathLibraryFolder>libglfw3.a