CMake:在make build期间找不到库

问题描述 投票:0回答:1

我正在尝试设置一个工作区,在那里我可以尝试GLib教程。我不熟悉C编程以及进行构建。

运行make命令时出现以下错误。

/Applications/CMake.app/Contents/bin/cmake -S/Users/foo/workspaces/personal/c/glib_tut/hello_world -B/Users/foo/workspaces/personal/c/glib_tut/hello_world --check-build-system CMakeFiles/Makefile.cmake 0
/Applications/CMake.app/Contents/bin/cmake -E cmake_progress_start /Users/foo/workspaces/personal/c/glib_tut/hello_world/CMakeFiles /Users/foo/workspaces/personal/c/glib_tut/hello_world/CMakeFiles/progress.marks
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/Makefile2 all
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/depend
cd /Users/foo/workspaces/personal/c/glib_tut/hello_world && /Applications/CMake.app/Contents/bin/cmake -E cmake_depends "Unix Makefiles" /Users/foo/workspaces/personal/c/glib_tut/hello_world /Users/foo/workspaces/personal/c/glib_tut/hello_world /Users/foo/workspaces/personal/c/glib_tut/hello_world /Users/foo/workspaces/personal/c/glib_tut/hello_world /Users/foo/workspaces/personal/c/glib_tut/hello_world/CMakeFiles/hello.dir/DependInfo.cmake --color=
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/hello.dir/build.make CMakeFiles/hello.dir/build
[ 50%] Linking C executable hello
/Applications/CMake.app/Contents/bin/cmake -E cmake_link_script CMakeFiles/hello.dir/link.txt --verbose=1
/Library/Developer/CommandLineTools/usr/bin/cc  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/hello.dir/src/hello.c.o  -o hello  -lglib-2.0 -lintl
ld: library not found for -lglib-2.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [hello] Error 1
make[1]: *** [CMakeFiles/hello.dir/all] Error 2
make: *** [all] Error 2

以下是我的CmakeLists.txt

cmake_minimum_required(VERSION 3.10)

project (hello_world_project)
include_directories(include)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB REQUIRED glib-2.0)

message(INFO "libs:" ${GLIB_LIBRARIES})
message(INFO "includes:" ${GLIB_INCLUDE_DIRS})

file(GLOB SOURCES "src/*.c")

#Create an executable
add_executable(hello ${SOURCES})

target_include_directories(hello PUBLIC 
    ${GLIB_INCLUDE_DIRS}
)

target_link_libraries(hello PUBLIC 
    ${GLIB_LIBRARIES}
)

我的cmake命令成功完成,并显示以下日志:

-- The C compiler identification is AppleClang 10.0.1.10010046
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Checking for module 'glib-2.0'
--   Found glib-2.0, version 2.62.5
INFOlibs:glib-2.0intl
INFOincludes:/usr/local/Cellar/glib/2.62.5/include/glib-2.0/usr/local/Cellar/glib/2.62.5/lib/glib-2.0/include/usr/local/opt/gettext/include/usr/local/Cellar/pcre/8.44/include
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/foo/workspaces/personal/c/glib_tut/hello_world

有人可以指导我解决此问题吗?在此先感谢

c makefile cmake glib
1个回答
0
投票

Static Library出现的Static Linker是编译时错误

ld: library not found for -l<Library_name>

没有包含Library not found for的库路径,则会出现错误Library Search Paths。>

ld表示Static Linker,它找不到库的位置。作为开发人员,您应该帮助链接程序并指向Library Search Paths

Build Settings -> Search Paths -> Library Search Paths
© www.soinside.com 2019 - 2024. All rights reserved.