英文:
CMake and make looking for libjawt.so file in the wrong place
问题
我有一个C++、Java和CMake项目,但目前无法编译它。我遇到了以下错误。
make[2]: *** 没有找到匹配的规则以构建目标 '/usr/lib/jvm/default/jre/lib/amd64/libjawt.so',需要它来构建目标 'build/Ygor'。 停止。
根据我在网上阅读的内容,这意味着编译器找不到该文件,要么它正在错误的位置查找,要么该文件不存在。果然,在错误的位置上。在我的电脑上,libjawt.so 文件实际上位于 /usr/lib/jvm/default/lib/libjawt.so
。在 /usr/lib/jvm/default/
中没有 jre
文件夹。
我希望编译器能够准确地找到它要寻找的文件,无论是自动还是通过告诉它文件在哪里。然而,我不知道如何向编译器表达这一点。我尝试将 include_directories("/usr/lib/jvm/default/lib")
添加到最上层的 CMakeLists.txt 文件,但这没有改变任何东西。我知道有 add_library
和 find_library
这两个 CMake 函数,但如果它们能在这种情况下帮助我,我不知道如何使用它们来做到这一点。
下面是完整的编译器输出。
正在扫描目标 CommandParser 的依赖项
[ 7%] 正在构建目标文件 src/CMakeFiles/CommandParser.dir/CommandParser.cpp.o
[ 14%] 正在链接 CXX 静态库 libCommandParser.a
[ 14%] 已构建目标 CommandParser
正在扫描目标 Item 的依赖项
[ 21%] 正在构建目标文件 src/CMakeFiles/Item.dir/Item.cpp.o
[ 28%] 正在链接 CXX 静态库 libItem.a
[ 28%] 已构建目标 Item
正在扫描目标 Dependency 的依赖项
[ 35%] 正在构建目标文件 src/CMakeFiles/Dependency.dir/dependency.cpp.o
[ 42%] 正在链接 CXX 静态库 libDependency.a
[ 42%] 已构建目标 Dependency
正在扫描目标 Parser 的依赖项
[ 50%] 正在构建目标文件 src/CMakeFiles/Parser.dir/Parser.cpp.o
[ 57%] 正在链接 CXX 静态库 libParser.a
[ 57%] 已构建目标 Parser
正在扫描目标 Actor 的依赖项
[ 64%] 正在构建目标文件 src/CMakeFiles/Actor.dir/Actor.cpp.o
[ 71%] 正在链接 CXX 静态库 libActor.a
[ 71%] 已构建目标 Actor
正在扫描目标 Room 的依赖项
[ 78%] 正在构建目标文件 src/CMakeFiles/Room.dir/Room.cpp.o
[ 85%] 正在链接 CXX 静态库 libRoom.a
[ 85%] 已构建目标 Room
正在扫描目标 Ygor 的依赖项
[ 92%] 正在构建目标文件 CMakeFiles/Ygor.dir/src/main.cpp.o
make[2]: *** 没有找到匹配的规则以构建目标 '/usr/lib/jvm/default/jre/lib/amd64/libjawt.so',需要它来构建目标 'build/Ygor'。 停止。
make[1]: *** [CMakeFiles/Makefile2:131: CMakeFiles/Ygor.dir/all] 错误 2
make: *** [Makefile:104: all] 错误 2
这是最上层的 CMakeLists.txt 文件。
cmake_minimum_required (VERSION 2.6)
project (Ygor)
# 版本号
set (Ygor_VERSION_MAJOR 0)
set (Ygor_VERSION_MINOR 1)
set (Ygor_VERSION "${Ygor_VERSION_MAJOR}.${Ygor_VERSION_MINOR}")
# 输出路径
set (EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/build")
# 包含路径
include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_SOURCE_DIR}/build")
include_directories ("${PROJECT_SOURCE_DIR}/build/include")
include_directories ("${PROJECT_SOURCE_DIR}/build/include/linux")
include_directories ("${PROJECT_SOURCE_DIR}/build/stanford-corenlp")
include_directories ("/usr/lib/jvm/default/lib")
add_subdirectory (src)
# 查找 JNI 包
find_package(JNI)
if (JNI_FOUND)
include_directories("${JNI_INCLUDE_DIRS}")
endif()
add_executable (Ygor src/main.cpp)
target_link_libraries (Ygor Parser)
target_link_libraries (Ygor Dependency)
target_link_libraries (Ygor CommandParser)
target_link_libraries (Ygor Actor)
target_link_libraries (Ygor Item)
target_link_libraries (Ygor Room)
if (JNI_FOUND)
target_link_libraries (Ygor ${JNI_LIBRARIES})
endif()
英文:
I have a C++, Java, and CMake project but I am, at the moment, unable to compile it. I encounter the following error.
make[2]: *** No rule to make target '/usr/lib/jvm/default/jre/lib/amd64/libjawt.so', needed by 'build/Ygor'. Stop.
From what I've read online that means the compiler cannot find that file, either it's looking in the wrong place or it doesn't exist. Sure enough, it's in the wrong place. On my computer the libjawt.so file is actually located at /usr/lib/jvm/default/lib/libjawt.so
. There is no jre
in /usr/lib/jvm/default/
.
I would like for the compiler to accurately locate the file it's looking for. Either automatically or by me telling it where it is. However I am at a loss as to how to express this to the compiler. I've tried to add include_directories("/usr/lib/jvm/default/lib")
to the uppermost CMakeLists.txt file but that changes nothing. I am aware of the add_library
and find_library
CMake functions but if they could help me in this situation I don't know how to use them to do that.
Here is the full compiler output.
Scanning dependencies of target CommandParser
[ 7%] Building CXX object src/CMakeFiles/CommandParser.dir/CommandParser.cpp.o
[ 14%] Linking CXX static library libCommandParser.a
[ 14%] Built target CommandParser
Scanning dependencies of target Item
[ 21%] Building CXX object src/CMakeFiles/Item.dir/Item.cpp.o
[ 28%] Linking CXX static library libItem.a
[ 28%] Built target Item
Scanning dependencies of target Dependency
[ 35%] Building CXX object src/CMakeFiles/Dependency.dir/dependency.cpp.o
[ 42%] Linking CXX static library libDependency.a
[ 42%] Built target Dependency
Scanning dependencies of target Parser
[ 50%] Building CXX object src/CMakeFiles/Parser.dir/Parser.cpp.o
[ 57%] Linking CXX static library libParser.a
[ 57%] Built target Parser
Scanning dependencies of target Actor
[ 64%] Building CXX object src/CMakeFiles/Actor.dir/Actor.cpp.o
[ 71%] Linking CXX static library libActor.a
[ 71%] Built target Actor
Scanning dependencies of target Room
[ 78%] Building CXX object src/CMakeFiles/Room.dir/Room.cpp.o
[ 85%] Linking CXX static library libRoom.a
[ 85%] Built target Room
Scanning dependencies of target Ygor
[ 92%] Building CXX object CMakeFiles/Ygor.dir/src/main.cpp.o
make[2]: *** No rule to make target '/usr/lib/jvm/default/jre/lib/amd64/libjawt.so', needed by 'build/Ygor'. Stop.
make[1]: *** [CMakeFiles/Makefile2:131: CMakeFiles/Ygor.dir/all] Error 2
make: *** [Makefile:104: all] Error 2
And here is the uppermost CMakeLists.txt file.
cmake_minimum_required (VERSION 2.6)
project (Ygor)
# Version Numbers
set (Ygor_VERSION_MAJOR 0)
set (Ygor_VERSION_MINOR 1)
set (Ygor_VERSION "${Ygor_VERSION_MAJOR}.${Ygor_VERSION_MINOR}")
# Output
set (EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/build")
# Include directories
include_directories ("${PROJECT_SOURCE_DIR}/src")
include_directories ("${PROJECT_SOURCE_DIR}/build")
include_directories ("${PROJECT_SOURCE_DIR}/build/include")
include_directories ("${PROJECT_SOURCE_DIR}/build/include/linux")
include_directories ("${PROJECT_SOURCE_DIR}/build/stanford-corenlp")
include_directories ("/usr/lib/jvm/default/lib")
add_subdirectory (src)
# Find the JNI package
find_package(JNI)
if (JNI_FOUND)
include_directories("${JNI_INCLUDE_DIRS}")
endif()
add_executable (Ygor src/main.cpp)
target_link_libraries (Ygor Parser)
target_link_libraries (Ygor Dependency)
target_link_libraries (Ygor CommandParser)
target_link_libraries (Ygor Actor)
target_link_libraries (Ygor Item)
target_link_libraries (Ygor Room)
if (JNI_FOUND)
target_link_libraries (Ygor ${JNI_LIBRARIES})
endif()
答案1
得分: 1
通过调用以下代码行:
find_package(JNI)
CMake提供了多个JNI缓存变量,允许您指定相关库的位置(如果未找到或找到的库不正确)。您可以在项目的命令行上运行 cmake
来查看缓存变量的列表:
cmake -LA
这在CMake GUI中也很容易查看。如果 JAVA_AWT_LIBRARY
变量的值不正确,您可以再次运行CMake,为该变量提供更新后的值:
cmake -DJAVA_AWT_LIBRARY=/usr/lib/jvm/default/lib/libjawt.so ..
英文:
By calling the line:
find_package(JNI)
CMake provides several JNI cache variables that allow you to specify the location of the associated libraries (if not found or found libraries are not correct). You can run cmake
from the command line on your project to see a list of the cache variables:
cmake -LA
This is also easily viewable in the CMake GUI. If the value for the JAVA_AWT_LIBRARY
variable is incorrect, you can run CMake again, providing an updated value for that variable:
cmake -DJAVA_AWT_LIBRARY=/usr/lib/jvm/default/lib/libjawt.so ..
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论