我有一个使用CMake的C ++项目,然后使用该项目生成没有问题的忍者项目。我试图生成一个Xcode项目,但是当我尝试构建它时,出现一个错误,提示找不到.o文件:
clang: error: no such file or directory: '/Users/ruihpacheco/chi/databaseclient/build_xcode/src/databaseclient.build/Debug/databaseclient.build/Objects-normal/x86_64/connection.o'
clang: error: no such file or directory: '/Users/ruihpacheco/chi/databaseclient/build_xcode/src/databaseclient.build/Debug/databaseclient.build/Objects-normal/x86_64/utils.o'
clang: error: no such file or directory: '/Users/ruihpacheco/chi/databaseclient/build_xcode/src/databaseclient.build/Debug/databaseclient.build/Objects-normal/x86_64/state_machines.o'
clang: error: no such file or directory: '/Users/ruihpacheco/chi/databaseclient/build_xcode/src/databaseclient.build/Debug/databaseclient.build/Objects-normal/x86_64/parsers.o'
clang: error: no such file or directory: '/Users/ruihpacheco/chi/databaseclient/build_xcode/src/databaseclient.build/Debug/databaseclient.build/Objects-normal/x86_64/generators.o'
检查目录显示这些文件似乎存在,但名称不同:
> la src/databaseclient.build/Debug/databaseclient.build/Objects-normal/x86_64/ Thu Jan 24 15:14:07 2019
total 23536
drwxr-xr-x 63 ruihpacheco staff 2.0K Jan 24 15:14 .
drwxr-xr-x 4 ruihpacheco staff 128B Jan 24 15:14 ..
-rw-r--r-- 1 ruihpacheco staff 37K Jan 24 15:14 abstract_connection.d
-rw-r--r-- 1 ruihpacheco staff 825K Jan 24 15:14 abstract_connection.dia
-rw-r--r-- 1 ruihpacheco staff 883K Jan 24 15:14 abstract_connection.o
-rw-r--r-- 1 ruihpacheco staff 662B Jan 24 15:14 abstract_result.d
-rw-r--r-- 1 ruihpacheco staff 6.8K Jan 24 15:14 abstract_result.dia
-rw-r--r-- 1 ruihpacheco staff 232K Jan 24 15:14 abstract_result.o
-rw-r--r-- 1 ruihpacheco staff 37K Jan 24 15:14 connection-4F0435C11320AC72.d
-rw-r--r-- 1 ruihpacheco staff 895K Jan 24 15:14 connection-4F0435C11320AC72.dia
-rw-r--r-- 1 ruihpacheco staff 610K Jan 24 15:14 connection-4F0435C11320AC72.o
-rw-r--r-- 1 ruihpacheco staff 151B Jan 24 15:14 connection-A95D7C1FAB89AE69.d
-rw-r--r-- 1 ruihpacheco staff 220B Jan 24 15:14 connection-A95D7C1FAB89AE69.dia
-rw-r--r-- 1 ruihpacheco staff 50K Jan 24 15:14 connection-A95D7C1FAB89AE69.o
-rw-r--r-- 1 ruihpacheco staff 37K Jan 24 15:14 connection-CC26C77ACFAB6964.d
-rw-r--r-- 1 ruihpacheco staff 912K Jan 24 15:14 connection-CC26C77ACFAB6964.dia
-rw-r--r-- 1 ruihpacheco staff 1.0M Jan 24 15:14 connection-CC26C77ACFAB6964.o
-rw-r--r-- 1 ruihpacheco staff 2.9K Jan 24 15:14 databaseclient.LinkFileList
-rw-r--r-- 1 ruihpacheco staff 230B Jan 24 15:14 error_code.d
-rw-r--r-- 1 ruihpacheco staff 220B Jan 24 15:14 error_code.dia
-rw-r--r-- 1 ruihpacheco staff 71K Jan 24 15:14 error_code.o
-rw-r--r-- 1 ruihpacheco staff 828B Jan 24 15:14 generators-2BF46CDAE4191A6E.d
-rw-r--r-- 1 ruihpacheco staff 8.5K Jan 24 15:14 generators-2BF46CDAE4191A6E.dia
-rw-r--r-- 1 ruihpacheco staff 218K Jan 24 15:14 generators-2BF46CDAE4191A6E.o
-rw-r--r-- 1 ruihpacheco staff 548B Jan 24 15:14 generators-AB4B789D17316956.d
-rw-r--r-- 1 ruihpacheco staff 6.8K Jan 24 15:14 generators-AB4B789D17316956.dia
-rw-r--r-- 1 ruihpacheco staff 415K Jan 24 15:14 generators-AB4B789D17316956.o
-rw-r--r-- 1 ruihpacheco staff 36K Jan 24 15:14 listener.d
-rw-r--r-- 1 ruihpacheco staff 978K Jan 24 15:14 listener.dia
-rw-r--r-- 1 ruihpacheco staff 1.2M Jan 24 15:14 listener.o
-rw-r--r-- 1 ruihpacheco staff 132B Jan 24 15:14 md5.d
-rw-r--r-- 1 ruihpacheco staff 220B Jan 24 15:14 md5.dia
-rw-r--r-- 1 ruihpacheco staff 95K Jan 24 15:14 md5.o
-rw-r--r-- 1 ruihpacheco staff 673B Jan 24 15:14 parsers-404CED0A5A8A6B5B.d
-rw-r--r-- 1 ruihpacheco staff 6.7K Jan 24 15:14 parsers-404CED0A5A8A6B5B.dia
-rw-r--r-- 1 ruihpacheco staff 320K Jan 24 15:14 parsers-404CED0A5A8A6B5B.o
-rw-r--r-- 1 ruihpacheco staff 666B Jan 24 15:14 parsers-704FC03E3B6B0880.d
-rw-r--r-- 1 ruihpacheco staff 6.4K Jan 24 15:14 parsers-704FC03E3B6B0880.dia
-rw-r--r-- 1 ruihpacheco staff 501K Jan 24 15:14 parsers-704FC03E3B6B0880.o
-rw-r--r-- 1 ruihpacheco staff 222B Jan 24 15:14 result.d
-rw-r--r-- 1 ruihpacheco staff 220B Jan 24 15:14 result.dia
-rw-r--r-- 1 ruihpacheco staff 53K Jan 24 15:14 result.o
-rw-r--r-- 1 ruihpacheco staff 134B Jan 24 15:14 sha1.d
-rw-r--r-- 1 ruihpacheco staff 648B Jan 24 15:14 sha1.dia
-rw-r--r-- 1 ruihpacheco staff 82K Jan 24 15:14 sha1.o
-rw-r--r-- 1 ruihpacheco staff 149B Jan 24 15:14 sql_state.d
-rw-r--r-- 1 ruihpacheco staff 220B Jan 24 15:14 sql_state.dia
-rw-r--r-- 1 ruihpacheco staff 94K Jan 24 15:14 sql_state.o
-rw-r--r-- 1 ruihpacheco staff 903B Jan 24 15:14 state_machines-286E024B50293C5A.d
-rw-r--r-- 1 ruihpacheco staff 7.0K Jan 24 15:14 state_machines-286E024B50293C5A.dia
-rw-r--r-- 1 ruihpacheco staff 357K Jan 24 15:14 state_machines-286E024B50293C5A.o
-rw-r--r-- 1 ruihpacheco staff 482B Jan 24 15:14 state_machines-79E86DDB3D33788F.d
-rw-r--r-- 1 ruihpacheco staff 6.1K Jan 24 15:14 state_machines-79E86DDB3D33788F.dia
-rw-r--r-- 1 ruihpacheco staff 200K Jan 24 15:14 state_machines-79E86DDB3D33788F.o
-rw-r--r-- 1 ruihpacheco staff 313B Jan 24 15:14 utils-8D3E37120512868D.d
-rw-r--r-- 1 ruihpacheco staff 5.5K Jan 24 15:14 utils-8D3E37120512868D.dia
-rw-r--r-- 1 ruihpacheco staff 86K Jan 24 15:14 utils-8D3E37120512868D.o
-rw-r--r-- 1 ruihpacheco staff 523B Jan 24 15:14 utils-A68FF56E16A77975.d
-rw-r--r-- 1 ruihpacheco staff 7.4K Jan 24 15:14 utils-A68FF56E16A77975.dia
-rw-r--r-- 1 ruihpacheco staff 113K Jan 24 15:14 utils-A68FF56E16A77975.o
-rw-r--r-- 1 ruihpacheco staff 420B Jan 24 15:14 utils-C6A6E2A9DFE20FA6.d
-rw-r--r-- 1 ruihpacheco staff 5.8K Jan 24 15:14 utils-C6A6E2A9DFE20FA6.dia
-rw-r--r-- 1 ruihpacheco staff 223K Jan 24 15:14 utils-C6A6E2A9DFE20FA6.o
这似乎是Xcode的问题,因为我的项目有几个类,分别称为connection
,generators
,parsers
,state_machines
和utils
,但在不同的名称空间。
主要CMakeLists.txt:
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt.")
endif (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif (CCACHE_PROGRAM)
project(databaseclient LANGUAGES CXX VERSION 0.1.0.0 DESCRIPTION)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE DEBUG)
endif(NOT CMAKE_BUILD_TYPE)
add_subdirectory(src)
add_library(${PROJECT_NAME}_shared SHARED $<TARGET_OBJECTS:${PROJECT_NAME}>)
add_library(${PROJECT_NAME}_static STATIC $<TARGET_OBJECTS:${PROJECT_NAME}>)
# Added here so we can run ctest from the root directory of the project.
enable_testing()
add_subdirectory(tests)
在src /下的CMakeLists.txt:
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
set(
INCLUDES
${PROJECT_SOURCE_DIR}/include/databaseclient/parameters.hpp
${PROJECT_SOURCE_DIR}/include/databaseclient/connection.hpp
${PROJECT_SOURCE_DIR}/include/databaseclient/sql_state.hpp
${PROJECT_SOURCE_DIR}/include/databaseclient/collation.hpp
${PROJECT_SOURCE_DIR}/include/databaseclient/error_code.hpp
${PROJECT_SOURCE_DIR}/include/databaseclient/result.hpp
)
set(
MAIN
${PROJECT_SOURCE_DIR}/src/connection.cpp
${PROJECT_SOURCE_DIR}/src/sql_state.cpp
${PROJECT_SOURCE_DIR}/src/result.cpp
)
set(
DETAIL
${PROJECT_SOURCE_DIR}/src/detail/types.hpp
${PROJECT_SOURCE_DIR}/src/detail/listener.hpp
${PROJECT_SOURCE_DIR}/src/detail/listener.cpp
${PROJECT_SOURCE_DIR}/src/detail/error_code.hpp
${PROJECT_SOURCE_DIR}/src/detail/error_code.cpp
${PROJECT_SOURCE_DIR}/src/detail/md5.hpp
${PROJECT_SOURCE_DIR}/src/detail/md5.cpp
${PROJECT_SOURCE_DIR}/src/detail/sha1.hpp
${PROJECT_SOURCE_DIR}/src/detail/sha1.cpp
${PROJECT_SOURCE_DIR}/src/detail/utils.hpp
${PROJECT_SOURCE_DIR}/src/detail/utils.cpp
${PROJECT_SOURCE_DIR}/src/detail/abstract_result.hpp
${PROJECT_SOURCE_DIR}/src/detail/abstract_result.cpp
${PROJECT_SOURCE_DIR}/src/detail/abstract_connection.hpp
${PROJECT_SOURCE_DIR}/src/detail/abstract_connection.cpp
)
set(
PG
${PROJECT_SOURCE_DIR}/src/detail/pg/connection.cpp
${PROJECT_SOURCE_DIR}/src/detail/pg/connection.hpp
${PROJECT_SOURCE_DIR}/src/detail/pg/utils.hpp
${PROJECT_SOURCE_DIR}/src/detail/pg/utils.cpp
${PROJECT_SOURCE_DIR}/src/detail/pg/state_machines.hpp
${PROJECT_SOURCE_DIR}/src/detail/pg/state_machines.cpp
${PROJECT_SOURCE_DIR}/src/detail/pg/parsers.hpp
${PROJECT_SOURCE_DIR}/src/detail/pg/parsers.cpp
${PROJECT_SOURCE_DIR}/src/detail/pg/generators.hpp
${PROJECT_SOURCE_DIR}/src/detail/pg/generators.cpp
)
set(
MDB
${PROJECT_SOURCE_DIR}/src/detail/mdb/connection.cpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/connection.hpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/utils.hpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/utils.cpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/state_machines.hpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/state_machines.cpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/parsers.hpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/parsers.cpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/generators.hpp
${PROJECT_SOURCE_DIR}/src/detail/mdb/generators.cpp
)
source_group(
"include"
FILES
${INCLUDES}
)
source_group(
""
FILES
${MAIN}
)
source_group(
"detail"
FILES
${DETAIL}
)
source_group(
"detail\\pg"
FILES
${PG}
)
source_group(
"detail\\mdb"
FILES
${MDB}
)
add_library(
${PROJECT_NAME}
OBJECT
${INCLUDES}
${MAIN}
${DETAIL}
${PG}
${MDB}
)
set_target_properties(
${PROJECT_NAME}
PROPERTIES
VERSION ${PROJECT_VERSION}
POSITION_INDEPENDENT_CODE ON
)
target_compile_features(
${PROJECT_NAME}
PUBLIC
cxx_std_11
cxx_auto_type
cxx_constexpr
cxx_deleted_functions
cxx_inline_namespaces
cxx_lambdas
cxx_noexcept
cxx_nullptr
cxx_override
cxx_range_for
)
target_compile_definitions(
${PROJECT_NAME}
PRIVATE
ASIO_STANDALONE=1
ASIO_NO_EXCEPTIONS=1
ASIO_NO_DEPRECATED=1
)
target_include_directories(
${PROJECT_NAME}
PUBLIC
${PROJECT_SOURCE_DIR}/include/
PRIVATE
${byte-lite_SOURCE_DIR}/include/nonstd
${asio_SOURCE_DIR}/asio/include/
)
if (UNIX)
if (CMAKE_BUILD_TYPE MATCHES DEBUG)
target_compile_options(${PROJECT_NAME} PRIVATE -g)
endif (CMAKE_BUILD_TYPE MATCHES DEBUG)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(${PROJECT_NAME} PRIVATE -Wundefined-func-template -Weverything -ferror-limit=0 -fcolor-diagnostics -Wno-c++98-compat -Wno-documentation -Wno-c++98-compat-pedantic -Wno-weak-vtables -Wno-global-constructors -Wno-exit-time-destructors)
if (CMAKE_BUILD_TYPE MATCHES DEBUG)
# -O1 -fno-optimize-sibling-calls -Wthread-safety -fsanitize=undefined -fsanitize=integer -fsanitize=nullability -fsanitize=address
target_compile_options(${PROJECT_NAME} PRIVATE -glldb -D_FORTIFY_SOURCE=2)
endif (CMAKE_BUILD_TYPE MATCHES DEBUG)
endif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
target_compile_definitions(${PROJECT_NAME} PRIVATE _GLIBCXX_USE_C99 _GLIBCXX_USE_C99_MATH _GLIBCXX_USE_C99_MATH_TR1)
target_compile_options(${PROJECT_NAME} PRIVATE -lstdc++ -rpath=/usr/local/lib/gcc48)
endif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
endif (UNIX)
答案 0 :(得分:0)
我通过删除OBJECT目标并仅创建静态库来解决此问题。