编辑我在Windows上使用MinGW-x86_64
当我尝试使用cmake编译gtk + 3 c项目时,我在日志中出现此错误消息:
"C:\Program Files\JetBrains\CLion 2017.1.3\bin\cmake\bin\cmake.exe" --build C:\Users\Jonas\ClionProjects\tutorial\cmake-build-debug --target tutorial -- -j 4
[ 50%] Linking C executable tutorial.exe
c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../../mingw32/bin/ld.exe: cannot find -ldwmapi
collect2.exe: error: ld returned 1 exit status
CMakeFiles\tutorial.dir\build.make:96: recipe for target 'tutorial.exe' failed
mingw32-make.exe[3]: *** [tutorial.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/tutorial.dir/all] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/tutorial.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/tutorial.dir/rule' failed
mingw32-make.exe[1]: *** [CMakeFiles/tutorial.dir/rule] Error 2
mingw32-make.exe: *** [tutorial] Error 2
Makefile:117: recipe for target 'tutorial' failed
这是我的CMakeLists.txt,在那里我添加了gtk3及其库,但是当我尝试编译时,它有前面提到的错误。
cmake_minimum_required(VERSION 3.7)
project(tutorial)
set(CMAKE_C_STANDARD 99)
set(SOURCE_FILES main.c)
set(PKG_CONFIG_EXECUTABLE "C:/msys64/mingw64/bin/pkg-config.exe")
FIND_PACKAGE(PkgConfig REQUIRED)
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0)
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS})
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS})
add_executable(tutorial ${SOURCE_FILES})
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER})
TARGET_LINK_LIBRARIES(tutorial ${GTK3_LIBRARIES})
答案 0 :(得分:0)
dwmapi.dll仅适用于Vista。所以我猜这是一个gtk + -3.0包的bug。您的操作系统不需要-ldwmapi
。以下是解决此问题的解决方法。我不确定这会解决您的问题。请注意,这是自我责任。
C:\msys64\mingw64\lib\pkgconfig
-ldwmapi
和:wq
让我们创建libdwmapi.a
dlltool -d dwmapi.def -l libdwmapi.a