更新CMake(似乎已经)破坏了我的程序 [英] Updating CMake (seems to have) broke my program

查看:69
本文介绍了更新CMake(似乎已经)破坏了我的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从CMake 3.6更新到了最新版本(3.12.0-rc2),现在我的程序之一无法编译.

I updated from CMake 3.6 to whatever the latest version is (3.12.0-rc2) and now one of my programs won't compile.

奇怪的是,错误消息显示了标准库本身中的未定义符号.这是错误消息:

The weird thing is, the error message shows undefined symbols from in the standard library itself. Here's the error message:

Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(char const*)", referenced from:
      GetName() in ncc.cpp.o
      Expression() in ncc.cpp.o
      Term() in ncc.cpp.o
      GetNum() in ncc.cpp.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string()", referenced from:
      GetName() in ncc.cpp.o
      GetNum() in ncc.cpp.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator+=(char)", referenced from:
      GetName() in ncc.cpp.o
      GetNum() in ncc.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [ncc] Error 1
make[1]: *** [CMakeFiles/ncc.dir/all] Error 2
make: *** [all] Error 2

我该如何解决?我需要链接到标准库的其他版本吗?如果是这样,我该如何告诉CMake?

How do I fix this? Do I need to link to a different version of the standard library? And if so, how I tell CMake that?

这是我的CMakeLists.txt文件:

Here's my CMakeLists.txt file:

cmake_minimum_required(VERSION 3.0)

project(ncc)

add_definitions(-std=c++14)

add_subdirectory(${CMAKE_SOURCE_DIR}/src/)

add_executable(ncc ${CompSource})
add_executable(ncc-opt ${OptSource})
add_executable(nci ${IntSource})

我尝试了add_definitions行,没有它,这似乎没有什么作用.

I tried it with the add_definitions line and without it, which didn't seem to make a difference.

这是运行make VERBOSE=1的相关输出:

Scanning dependencies of target ncc
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/ncc.dir/build.make CMakeFiles/ncc.dir/build
[ 83%] Building CXX object CMakeFiles/ncc.dir/src/ncc.cpp.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++    -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk   -std=c++14 -o CMakeFiles/ncc.dir/src/ncc.cpp.o -c /Users/nepps/Dropbox/Projects/ncc/src/ncc.cpp
[100%] Linking CXX executable ncc
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/ncc.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++   -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/ncc.dir/src/ncc.cpp.o  -o ncc 
Undefined symbols for architecture x86_64:
(same errors as above)

如果需要更多信息,请随时发表评论.我正在使用运行MacOS 10.13.3的MacBook Pro.

Feel free to comment if you need more information. I'm using a MacBook pro running MacOS 10.13.3.

推荐答案

好吧,我不确定为什么它起作用,但是程序中的所有功能都标记为static,并且删除该功能使错误消失了.走吧.

Well, I'm not sure why it worked, but all of the functions in the program were marked static and removing that made the errors go away. Go figure.

这篇关于更新CMake(似乎已经)破坏了我的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆