未明确引用``CLion

时间:2016-12-02 17:33:09

标签: c++ eclipse cmake clion

我正在尝试在CLION IDE中编译项目,但我无法成功,但我可以在Eclipse中编译完全相同的文件。 首先这是错误:

#include "library1.h"
#include "DataStructure.h"
void* Init() {
    DataStructure* DS(nullptr);
     try {
       DS = new DataStructure();
      } catch (std::bad_alloc &e) {
       delete DS;
       return nullptr;
        }
      return (void *)DS;
}

现在我已经包含了所请求的文件,例如在library1.cpp的源文件中 我有:

cmake_minimum_required(VERSION 3.5)
project(Besart)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -std=c++11 )
set(SOURCE_FILES  "Data Structures 1/HW 2/main.cpp"
    "Data Structures 1/HW 2/Creature.cpp" "Data Structures 1/HW 2/Magi.cpp"
    "Data Structures 1/HW 2/DataStructure.cpp/"
    "Data Structures 1/HW 2/library1.cpp")

add_executable(Besart ${SOURCE_FILES}  "Data Structures 1/HW 2/main.cpp"
    "Data Structures 1/HW 2/Creature.cpp"
     "Data Structures 1/HW 2/Magi.cpp"
    "Data Structures 1/HW 2/DataStructure.cpp/"
     "Data Structures 1/HW 2/library1.cpp")

但该文件在DataStructures.cpp中实现,并在DataStructure.h中声明 See image!!

最后这是CMake:

{{1}}

CMAKE

有人能看到问题并帮我在CLion中编译这个项目吗? 谢谢

1 个答案:

答案 0 :(得分:1)

你有错误/在Blob之后:

DataStructure.cpp

将其更改为:

set(SOURCE_FILES  "Data Structures 1/HW 2/main.cpp"
    "Data Structures 1/HW 2/Creature.cpp" "Data Structures 1/HW 2/Magi.cpp"
    "Data Structures 1/HW 2/DataStructure.cpp/"
    "Data Structures 1/HW 2/library1.cpp")

然后按以下方式修复add_executable():

  set(SOURCE_FILES  "Data Structures 1/HW 2/main.cpp"
        "Data Structures 1/HW 2/Creature.cpp" "Data Structures 1/HW 2/Magi.cpp"
        "Data Structures 1/HW 2/DataStructure.cpp"
        "Data Structures 1/HW 2/library1.cpp")

无需重复add_executable(Besart ${SOURCE_FILES}) 的内容。