我最近用Xcode 11.1安装了macos catalina,并更新了cmake,clang和llvm
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
$ cmake --version
cmake version 3.15.4
$ which cmake
/usr/local/bin/cmake
$ clang --version
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ which clang
/usr/bin/clang
CMakeLists.txt看起来如下:
cmake_minimum_required(VERSION 3.14)
project("ROZZETA" VERSION 0.0.1 LANGUAGES C)
# Allow us to import cmake scripts from ./cmake
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
# Compiler flags
set(CMAKE_C_COMPILER /usr/bin/clang CACHE PATH "")
find_package(GMP REQUIRED)
add_executable(Rozzeta main.c)
target_link_libraries(Rozzeta gmp libgmp libgmp.a)
cmake成功检测到gmp:
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=c++ -G "CodeBlocks - Unix Makefiles" /<path to project>
-- The C compiler identification is AppleClang 11.0.0.11000033
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Using toolchain file: .
-- Found GMP: /usr/local/include/gmp.h and /usr/local/lib/libgmp.a
-- Configuring done
-- Generating done
构建失败:
cmake --build .
Scanning dependencies of target Rozzeta
[ 50%] Building C object CMakeFiles/Rozzeta.dir/main.c.o
/Users/gajaka/CLionProjects/Rozzeta/main.c:4:10: fatal error: 'gmp.h' file not found
#include <gmp.h>
^~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/Rozzeta.dir/main.c.o] Error 1
make[1]: *** [CMakeFiles/Rozzeta.dir/all] Error 2
make: *** [all] Error 2
我已经手动编译了:
cc main.c -lgmp
任何人都可以帮助我吗?提前非常感谢
对我来说非常沮丧!我个人使用jetbrains的CLion,同时尝试构建用C / C ++编写的旧代码,但由于MacOS 10.15,Catalina删除了以前在Mojave中使用的C头文件pkg,这给了我错误。因此,找到了另一种解决方法并进行了尝试。
如果已安装XCode 11.1,则打开终端并运行以下命令:
xcode-select --install
然后,
sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
现在,你很好。尝试使用cmake进行构建。