对CMAKE项目功能的不确定引用
我真的很喜欢使用CMAKE将二进制文件包含在C/C ++ Mingw项目中。 我使用的是Clion,因为它是我最喜欢的IDE,但它的项目是基于CMAKE的。
通常,i有.dll file和.h file(.dll.a是可选的),并且我尝试了许多“ target_link_library”,“ find_package”等的变体“返回的0x0135”,这意味着
CMAKE的示例如下:
cmake_minimum_required(VERSION 3.22)
project(untitled)
set(CMAKE_CXX_STANDARD 23)
include_directories("SDL2/include")
add_subdirectory(SDL2)
add_executable(untitled main.cpp)
target_link_libraries(untitled SDL2)
结果:
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: CMakeFiles/untitled.dir/main.cpp.obj: in function `SDL_main':
F:/SoftwareProjects/untitled/main.cpp:16: undefined reference to `SDL_CreateWindow'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:24: undefined reference to `SDL_GetWindowSurface'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:26: undefined reference to `SDL_MapRGB'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:26: undefined reference to `SDL_FillRect'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:28: undefined reference to `SDL_UpdateWindowSurface'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:30: undefined reference to `SDL_Delay'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:32: undefined reference to `SDL_DestroyWindow'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:34: undefined reference to `SDL_Quit'
链接.dll的问题。 (和.dll.a)适当进行项目。 这与一个库无关。我的问题:我不明白如何以正确的方式链接它。请帮助我!
更新: 伙计们,为您的建议提供了很多帮助,但不仅在SDL2库中有问题。我期望有一些一般。 我有另一个例子:我找到了名为sigil的漂亮库( http://www.libsigil.com/ ) 。我独自编译所有内容,然后将其放在CMakelists.txt:
set(SIGIL_INCLUDE_DIR libs/include)
set(SIGIL_LIB_DIR libs/)
include_directories(${SIGIL_INCLUDE_DIR})
link_directories(${SIGIL_LIB_DIR})
add_executable(MyApplication main.cpp)
target_link_libraries(MyApplication sigil)
仍然可以获取对Sigil函数的不确定引用,或使用0x0135(找不到库)返回过程
I'm really stuck in including compiled binaries to C/C++ MinGW projects using CMake.
I'm using CLion because it's my favorite IDE but it's projects are CMake-based.
In common I have .dll file and .h file (.dll.a is optional) and I tried a lot of variations with "target_link_library", "find_package" and etc, but compiling of projects returns "undefined reference to %function_name% or "returned 0x0135" which means library not found.
Example of CMake looks like this:
cmake_minimum_required(VERSION 3.22)
project(untitled)
set(CMAKE_CXX_STANDARD 23)
include_directories("SDL2/include")
add_subdirectory(SDL2)
add_executable(untitled main.cpp)
target_link_libraries(untitled SDL2)
And the result:
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: CMakeFiles/untitled.dir/main.cpp.obj: in function `SDL_main':
F:/SoftwareProjects/untitled/main.cpp:16: undefined reference to `SDL_CreateWindow'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:24: undefined reference to `SDL_GetWindowSurface'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:26: undefined reference to `SDL_MapRGB'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:26: undefined reference to `SDL_FillRect'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:28: undefined reference to `SDL_UpdateWindowSurface'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:30: undefined reference to `SDL_Delay'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:32: undefined reference to `SDL_DestroyWindow'
C:\Program Files\JetBrains\CLion 2021.3.3\bin\mingw\bin/ld.exe: F:/SoftwareProjects/untitled/main.cpp:34: undefined reference to `SDL_Quit'
Everything is OK with header files. The problem in linking .dll (and .dll.a) to project properly.
This is not about one library. My problem: I don't understand how to link it in right way. Please help me guys!
UPDATE:
Guys, help you so much for your advices, but problem not in SDL2 library only. I expected something general.
I have another example: I found nice library called SIGIL (http://www.libsigil.com/). I compiled everything on my own and put this to CMakeLists.txt:
set(SIGIL_INCLUDE_DIR libs/include)
set(SIGIL_LIB_DIR libs/)
include_directories(${SIGIL_INCLUDE_DIR})
link_directories(${SIGIL_LIB_DIR})
add_executable(MyApplication main.cpp)
target_link_libraries(MyApplication sigil)
Still getting undefined references to sigil functions, or process return with 0x0135 (library not found)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论