我有一个非常简单的问题,关于C ++代码没有编译,可能是为了一些微不足道的疏忽。
我的项目结构如下:
Project
|
+--->build
|
+--->core
| |
| +---->core.h
|
+---->core.cpp
|
+---->driver.cpp
|
+---->CMakeLists.txt
列出没有业务逻辑的文件:
core.h
#ifndef CORE_H
#define CORE_H
class core
{
private:
int input;
public:
void func1();
inline void setInput(int input)
{
this->input = input;
}
};
#endif
core.cpp
#include "core.h"
void core::func1()
{
std::cout << "Hi there!" << endl;
}
driver.cpp
#include "core.h"
int main()
{
core c;
int a = 10;
c.setInput(a);
c.func1();
}
的CMakeLists.txt
project(Project)
cmake_minimum_required(VERSION 2.6)
set(header_search_path "core")
include_directories(${header_search_path})
add_library(lib_1 core.cpp)
target_include_directories(lib_1 PUBLIC ${header_search_path})
***Some additional stuff here for linking driver.cpp to external dependencies***
我使用
构建cmake ..
make -j8
调用make命令后,出现以下错误
CMakeFiles / driver.dir / driver.cpp.o:在函数
main': driver.cpp:(.text+0x8b8): undefined reference to
core :: func1()&#39; collect2:错误:ld返回1退出状态 CMakeFiles / driver.dir / build.make:153:目标&#39;驱动程序的配方&#39; 失败make [2]: * [driver]错误1 CMakeFiles / Makefile2:67:食谱 对于目标&#39; CMakeFiles / driver.dir / all&#39;失败了[1]:* [CMakeFiles / driver.dir / all]错误2 Makefile:83:目标的配方 &#39;所有&#39;失败了:*** [全部]错误2
任何帮助将不胜感激。
如果有帮助,我在Fedora 25上使用cmake版本3.6.2。