0
Structure of the "project":
->shop
---->cpp store.
---->shop. h
---->main.cpp
---->Cmakelists.txt
When I try to compile Vscode accuses that there are multiple denifications of class members. Being that if I put an inline in the header file it compiles.
[build] Starting build [proc] Executing command: C: Tools Cmake bin cmake.EXE --build "c:/Users/Henrique/Documents/My Projects/Loja/build" -config Debug --target all -- -j 10 [build] Scanning dependencies of target app [build] [ 66%] Building CXX Object Cmakefiles/app.dir/loja.cpp.obj [build] [ 66%] Building CXX Object Cmakefiles/app.dir/main.cpp.obj [build] [100%] Linking CXX Executable app.exe [build] c:/mingw/bin/.. /lib/gcc/mingw32/8.2.0/.. /.. /.. /mingw32/bin/Ld.exe: Cmakefiles app.dir/Objects. a(loja.cpp.obj): in Function
ZN4loja5helloERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE': [build] C:/Users/Henrique/Documents/My Projects/Loja/loja.cpp:13: multiple definition of
store::hello(Std::__cxx11::basic_string, Std::allocator > const&)'; Cmakefiles app.dir/Objects. a(main.cpp.obj):C:/Users/Henrique/Documents/My Projects/Loja/loja.cpp:13: first defined here [build] c:/mingw/bin/.. /lib/gcc/mingw32/8.2.0/.. /.. /.. /mingw32/bin/Ld.exe: Cmakefiles app.dir/Objects. a(loja.cpp.obj): in FunctionZlsRSoRK4loja': [build] C:/Users/Henrique/Documents/My Projects/Loja/loja.cpp:17: multiple definition of
Operator<<(Std::ostream&, store const&)'; Cmakefiles app.dir/Objects. a(main.cpp.obj):C:/Users/Henrique/Documents/My Projects/Loja/loja.cpp:17: first defined here [build] c:/mingw/bin/.. /lib/gcc/mingw32/8.2.0/.. /.. /.. /mingw32/bin/Ld.exe: Cmakefiles app.dir/Objects. a(loja.cpp.obj): in FunctionZrsRSiR4loja': [build] C:/Users/Henrique/Documents/My Projects/Loja/loja.cpp:22: multiple definition of
Operator>>(Std::istream&, store&)'; Cmakefiles app.dir/Objects. a(main.cpp.obj):C:/Users/Henrique/Documents/My Projects/Loja/loja.cpp:22: first defined here [build] collect2.exe: error: Ld returned 1 Exit status [build] Cmakefiles app.dir build.make:99: Recipe for target 'app.exe' failed [build] mingw32-make.exe2: * [app.exe] Error 1 [build] Cmakefiles Makefile2:967: Recipe for target 'Cmakefiles/app.dir/all' failed [build] mingw32-make.exe1: * [Cmakefiles/app.dir/all] Error 2 [build] Makefile:115: Recipe for target 'all' failed [build] mingw32-make.exe: *** [all] Error 2 [build] Build finished with Exit code 2
Why does this happen? And how to solve.
I need a systematic way to add libs and linkalas to the main program. There is a linkage between libraries as well.
– Dagdeloo
open another question with a project that has libs...this project that you have shown here does not have libs...and has a very strange thing: include de.cpp... it is very rare that this be necessary, and in this case here caused the errors of multiple definition
– zentrunix
The question is: how to properly line the store lib. h with the main program.
– Dagdeloo
its terminology is wrong: "store. h" is not a lib, is a include...lib would be a file. lib or . dll on Windows, and . so on Linux; cmake has several commands related to includes, but in this small project of yours it was not necessary to use these commands
– zentrunix
Now it all makes sense. So I need to learn how linhar includes to my main program. That’s it?
– Dagdeloo
I didn’t understand what you said, I don’t know what "linhar"
– zentrunix
I meant link. Sorry.
– Dagdeloo