注意,我在source scl_soruce enable devtoolset-6和rehl驱动程序中使用Centos 7(带有禁用的noveau)。gcc和通过devtoolset-6的g++版本显然是GNU 6.2.1。
注意:我还使用libc版本ldd (GNU libc) 2.17。
我在跟踪本教程介绍opengl,但现在我被困住了。我从格福网站下载了源代码,并按照教程进行构建(并且没有看到任何错误)。我尝试了从回购中提供的源代码和主构建,结果是相同的。
我将源文件解压缩到Home目录中,在其中运行cmake .,然后运行make,然后运行sudo make install,没有发生错误。
注我还使用了本教程中描述的高兴实用程序,使用了opengl 3.3,
我的文件结构如下:
cmake-build-debug
...
include
glad
KHR
CMakeLists.txt
glad.c
main.cpp这是我的源代码:
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
int main() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
std::cout << "Hello, World!" << std::endl;
return 0;
}还有我的CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(opengltest)
set(CMAKE_CXX_STANDARD 11)
include_directories("include/")
set(SOURCE_FILES main.cpp glad.c)
add_executable(opengltest ${SOURCE_FILES})
target_link_libraries(opengltest -L/usr/local/lib -lglfw3 -pthread -lGLU -lGL -lrt -lXrandr -lXxf86vm -lXi -lXinerama -lX11 -ldl)这是我得到的准确输出:
/home/centos/IDE/bin/cmake/bin/cmake --build /home/centos/IDEProjects/opengltest/cmake-build-debug --target opengltest -- -j 4
Scanning dependencies of target opengltest
gmake[3]: Warning: File `../include/KHR/khrplatform.h' has modification time 17724 s in the future
[ 66%] Building CXX object CMakeFiles/opengltest.dir/main.cpp.o
[ 66%] Building C object CMakeFiles/opengltest.dir/glad.c.o
[100%] Linking CXX executable opengltest
/usr/bin/ld: /usr/local/lib/libglfw3.a(init.c.o): unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
gmake[3]: *** [opengltest] Error 1
gmake[2]: *** [CMakeFiles/opengltest.dir/all] Error 2
gmake[1]: *** [CMakeFiles/opengltest.dir/rule] Error 2
gmake: *** [opengltest] Error 2发布于 2017-07-07 20:42:57
哇,这和Centos 7遇到的问题有关.Centos 7有着如此古老的g++版本,为了获得支持c++14的g++ ie版本,我不得不使用dev-toolset-6。这与当前的项目无关(显然我正在使用c++11 ),但关于c++11的问题是,默认情况下,它使用的是在/usr/bin/中找到的g++/gcc/gmake版本,这并不是g++ 6.2.1版本所在的地方。
我已经对使用C++14的项目修复了这个问题,进入您想要的项目的设置,并将下面的行粘贴到构建、执行、部署下面的CMake选项中:
-D CMAKE_CXX_COMPILER=/opt/rh/devtoolset-6/root/usr/bin/g++ -D CMAKE_C_COMPILER=/opt/rh/devtoolset-6/root/usr/bin/gcc这是g++现在的正确位置。当然,我可以做一些符号链接来修复它,但我之前曾假设,我在终端中找到正确版本(修改.bashrc)的解决方案也适用于clion。
当我一时兴起地测试c++14特性时,很明显这是行不通的。
为什么这是个问题?我用了两个非常不同的g++/gcc版本,用g++/gcc 6.2.1编译了我的GLFW,用4.7或其他什么来编译我的实际程序。这就是为什么我会犯这个奇怪的错误。
请注意,这只解决了奇怪的.txt问题,我的cmake文件也不正确,因为我忘记了目标Xcursor。新的cmake文件现在看起来如下所示:
cmake_minimum_required(VERSION 3.7)
project(opengltest)
set(CMAKE_CXX_STANDARD 11)
include_directories("include/")
set(SOURCE_FILES main.cpp glad.c)
add_executable(opengltest ${SOURCE_FILES})
target_link_libraries(opengltest -L/usr/local/lib -lglfw3 -pthread -lGLU -lGL -lrt -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -ldl)现在我没有错误了(我仍然有那个奇怪的时钟倾斜警告,我只是假设好的websystem有问题)。
https://stackoverflow.com/questions/44978053
复制相似问题