如何将一个 exe 项目链接到另一个 exe 项目中的类
How to link an exe project to the classes in another exe project
>假设你想对可执行文件中的类进行一些单元测试,但你不想将它们重构到一个库中,你可以在其中使用 cmake 中的target_link_libraries( target library )
添加库。
如何授予测试类对其他类的访问权限?
1( 使用其他项目的源文件构建测试项目? 另一件事
include_directories(${otherExeProjectDir})
set( SOURCE_FILES
main.cpp
tests.h
tests.cpp
${otherExeProjectDir}/otherclass1.h
${otherExeProjectDir}/otherclass2.h
)
2( 将测试项目与其他项目中的 obj 文件链接? 某种add_library( otherclass.obj )
疯狂?
3(
如果您的主要可执行源位置是简单的或平面的,那么这样的东西可以工作:
cmake_minimum_required(VERSION 3.9)
project(tests)
# Get main executable source location properties
get_target_property(exe_sources exe SOURCES)
get_target_property(exe_source_dir exe SOURCE_DIR)
# Remove main entry point file
list(REMOVE_ITEM exe_sources main.cpp)
# Add test sources
add_executable(test1 test1.cpp)
# Add exe sources to test (assumes sources are relative paths)
foreach(src IN LISTS exe_sources)
target_sources(test1 PRIVATE "${exe_source_dir}/${src}")
endforeach()
# Add exe include directories to test
target_include_directories(test1 PRIVATE
${exe_source_dir}
$<TARGET_PROPERTY:exe,INCLUDE_DIRECTORIES>)
否则,不幸的是,一般的解决方案是依赖一些外部信息,例如顶级源文件位置或将您自己的源属性添加到主可执行目标。
相关文章:
- 项目名称.exe 已触发断点
- 是否可以将 EXE 文件作为 lib 文件链接到另一个项目?
- 从Visual Studio项目到文件.exe(Qt)
- 如何将一个 exe 项目链接到另一个 exe 项目中的类
- 如何将本地文件嵌入从C 项目生成的EXE文件中
- 我的C++项目找不到.exe
- 在Visual Studio 2017中使用Qt库的CMake项目:运行exe时找不到Qt dll
- c++ 将项目导出到 exe
- 更改.exe文件版本(从C++项目)
- 如何将.EXE从C 项目复制到C#项目的输出目录
- 如何使用x64编译器使用MsBuild.exe编译大型c++项目
- 如何将EXE项目用作DLL
- 如何从.exe项目导入代码进行单元测试
- 是否可以将 VS C++ 项目生成的 DLL/EXE 项目存储在 NuGet 包中
- Visual Studio 中引用的 exe 项目上的链接器错误
- 尝试在与我的 EXE 项目相同的解决方案中引用 DLL 项目时,出现错误"无法打开包含文件:"iostream"
- 从单元测试.EXE项目引用VC++.EXE项目中的类
- 由于库与EXE项目中的编译器指令不匹配,内存损坏
- 如何不在Visual C++.exe项目中创建.lib和.exp文件
- Visual Studio C++:单元测试exe项目与谷歌测试