我正在尝试在依赖于外部 C 库 GSL 的 CLion 中使用 C++ 代码。
我创建了一个 CMakeLists.txt 文件:
cmake_minimum_required(VERSION 3.20)
project(untitled)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_COMPILER /usr/local/Cellar/gcc/11.1.0_1/bin/g++-11)
set(CMAKE_CXX_FLAGS " -std=c++17 -mpopcnt -L/usr/local/lib")
include_directories(${PROJECT_BINARY_DIR}/Include /usr/local/include)
add_executable(untitled main.cpp)
find_package(GSL REQUIRED)
include_directories(${GSL_INCLUDE_DIR})
target_link_libraries(untitled main.cpp GSL::gsl)
但是当我编译它时,我得到了以下错误:
[ 50%] Linking CXX executable untitled
ld: library not found for -lmain.cpp
collect2: error: ld returned 1 exit status
make[3]: *** [untitled] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2
关于可能导致这种情况的任何建议?