【发布时间】:2014-09-29 18:55:20
【问题描述】:
您可以在此处看到表单 (How to Specify the Compiler and To Compile Different Main Functions) 我是 CMake 新手,但我仍然有问题。上一个问题帮助我理解了CMake,但我仍然有问题。首先,即使我在 CMakeLists.txt 中写了以下几行
set(CMAKE_CXX_COMPILER /opt/local/bin/g++)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
使用的编译器似乎是 Clang 而不是 g++。另外在编译时(我摆脱了所有代码错误)我收到这条消息:
[ 33%] Built target Output
[ 66%] Built target Vector
Scanning dependencies of target Output_test
[100%] Building CXX object tests/CMakeFiles/Output_test.dir/output_test.cpp.o
Linking CXX executable Output_test
ld: library not found for -lIO
collect2: error: ld returned 1 exit status
make[2]: *** [tests/Output_test] Error 1
make[1]: *** [tests/CMakeFiles/Output_test.dir/all] Error 2
make: *** [all] Error 2
你知道我做错了什么吗?
编辑: 在根文件夹中
cmake_minimum_required (VERSION 2.8.11)
project (MC)
set(CMAKE_CXX_COMPILER /opt/local/bin/g++)
set(CMAKE_CXX_FLAGS "-Wall -std=c++11")
# Class definitions
add_subdirectory(IO)
add_subdirectory(math)
# Tests
add_subdirectory(tests)
在IO文件夹中:
add_library(Output Output.cpp)
【问题讨论】:
-
您可能想要编辑问题以包含检查
IO库的CMakeLists.txt文件部分。 -
@JoachimPileborg 完成,抱歉。
-
您是否尝试删除 CMake 生成的所有旧文件并重新开始?
-
@Svalorzen 是的,多次。
-
请不要试图通过在
CMakeLists.txt中设置CMAKE_CXX_COMPILER来强制CMake 使用特定的编译器。除非你在做交叉编译,否则弄乱这个变量是一个可怕的想法。相反,让用户选择正确的编译器when invokingcmakeon the command line。
标签: c++ compiler-errors cmake