【发布时间】:2016-07-31 00:48:43
【问题描述】:
我有一个 c++,opengl 项目。我一直在用这个命令的命令行编译:
g++ `pkg-config --cflags glfw3` -o test test.cpp Third_Party/glError.cpp Third_Party/glUtil.cpp Third_Party/gl_core_4_3.cpp Third_Party/glTexture.cpp Third_Party/glShader.cpp `pkg-config --static --libs glfw3` -std=c++11
我想改用 cmake,所以我创建了这个文件:
cmake_minimum_required(VERSION 3.2)
project(openGLTest)
add_definitions(-std=c++11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_BUILD_TYPE Release)
add_executable(openGLTest test.cpp Third_Party/glError.cpp Third_Party/glUtil.cpp Third_Party/gl_core_4_3.cpp Third_Party/glShader.cpp Third_Party/glTexture.cpp)
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(openGLTest ${GLFW_STATIC_LIBRARIES})
当我通过命令行编译和运行测试时,项目运行良好。但是当我使用 cmake 编译和运行 openGLTest 时,我得到了这个错误:
terminate called after throwing an instance of 'std::length_error'
what(): basic_string::_S_create
Aborted (core dumped)
为什么会发生这种情况,我可以做些什么来解决它?
【问题讨论】:
-
CMAKE_BUILD_TYPE等于 Release 可能会添加额外的编译/链接器标志。您可能会看到带有make V=1的完整编译行。这些附加标志通常不会破坏 正确 程序,因此它们出现问题通常意味着您的程序不正确。例如,它使用了一些导致 Undefine Behavior 的操作。 -
这对我来说有点不清楚。你是说有一个错误没有被命令行程序捕捉到但是被cmake程序捕捉到了?
-
there is an error that isn't caught by the command line program but is caught by the cmake program?- 是的,就是这样。更准确地说,这是使用某些标志集的编译未捕获到的错误,而是由其他编译器标志集捕获的错误。