C++, Clang: #including header with cpp not compile
I have a main method, main.cpp: #include "MyStruct.h" MyStruct.h: #ifndef MYPROJ_MYSTRUCT_H #define MYPROJ_MYSTRUCT_H #include bool function1(...){ ... } bool function2(...){ ... } struct MyStruct{ ... } #endif This compiles. However, when I add the cpp file to contain the function definitions, main.cpp: #include "MyStruct.h" MyStruct.h: #ifndef MYPROJ_MYSTRUCT_H #define MYPROJ_MYSTRUCT_H #include bool function1(...){ ... } bool function2(...){ ... } struct MyStruct{ ... } #endif MyStruct.cpp: #include "MyStruct.h" // and that's it Just by including the header file, I get linker errors as if I am importing the header multiple times; Here is the CMakeLists: cmake_minimum_required(VERSION 3.8) set(CMAKE_CXX_STANDARD 17) set(SOURCE_FILES main.cpp MyStruct.cpp) add_executable(my_proj ${SOURCE_FILES}) The errors are all caused by duplicate symbol errors. I don't know how to get this to work, as this is something I always do when using make and g++ and I never run into issues; I this problem doesn't happen when I use CMake with g++ on Cygwin/Windows (this is on MacOS).
1
# Users who requested the code (so far)
$5
Suggested price from buyers at which they’d buy
Potential revenues from requesters (actual revenues can be significantly higher)
Time of last request:on Feb 20, 2018
Tags:c++, cmake
If you own such codes, please set up an offer and then invite users to it by clicking on «Invite to offer».
If you’re also be willing to buy those codes then click on «I’d also buy it» (no commitment to buy, but please only click when you’re serious about it).
Tell people about Sellcodes and get 20-40% on every resulting sale!