I’m building a program just to increase my OOP skills. This is my project structure:
Project -.vscode -build -includes - ContactInfo.h - Customer.h - Owner.h - PersonalInfo.h - User.h -src - ContactInfo.cpp - Customer.cpp - Owner.cpp - PersonalInfo.cpp - User.cpp - wrapper.h - wrapper.cpp - main.cpp - CMakeLists.txt
The problem is when I type command
make
duplicate symbol '_key' in: CMakeFiles/make_test_project.dir/src/main.cpp.o CMakeFiles/make_test_project.dir/src/wrapper.cpp.o duplicate symbol '_customers' in: CMakeFiles/make_test_project.dir/src/main.cpp.o CMakeFiles/make_test_project.dir/src/wrapper.cpp.o ld: 2 duplicate symbols for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [make_test_project] Error 1 make[1]: *** [CMakeFiles/make_test_project.dir/all] Error 2 make: *** [all] Error 2
I can guess what’s happening here, I’m basically including
wrapper.h
main.cpp
wrapper.cpp
This is my
wrapper.h
#ifndef WRAPPER_H #define WRAPPER_H #include "../includes/Customer.h" #include <vector> #include <iostream> char key; void printUI(); void RunApplication(); PersonalInfo CreatePersonalInfo(std::string &, std::string &, int & ); ContactInfo CreateContactInfo(std::string &, std::string &, std::string &, int&); void DisplayAllCustomers(); void AddCustomerToList(Customer &); Customer CreateCustomer(PersonalInfo &, ContactInfo &); std::vector<Customer> customers; #endif
This is my
main.cpp
#include "wrapper.h" int main() { RunApplication(); }
This below is my
CMakeLists.txt
cmake_minimum_required(VERSION 3.13) project(cmake_test_project) set(CMAKE_CXX_STANDARD 17) add_executable(make_test_project src/main.cpp src/wrapper.cpp src/ContactInfo.cpp src/PersonalInfo.cpp src/Customer.cpp src/User.cpp)
Note: I’m not gonna share
wrapper.cpp
wrapper.h
wrapper.cpp
Please feel free to ask more information, Thanks.
Anonymous Asked question May 13, 2021
Recent Comments