Author
Topic: qu :- multiple definition of menu. (Read 256 times)

hi to all, I've centos 7 as client and centos 6.10 as mysql server in VM. I am trying to build a small project , sample project i got from internet, that is running in one single file(" main.cpp ") but when i try to make it in multiple files it stuck in following errors:-

I am sure you have not . Apparently your project uses multiple files so you have to include some headers in your main file. So either your headers are wrong and contain definitions instead of declarations or you even include the sources instead of the headers.

1) This is not a programming forum, so this type of question is out of scope...2) If you are using c++, use c++ features, capsule your variables in structs, and pass them around. Global variables are bad in every sense and only lead to messy code and strange behavior...3) Every time you use a header in a c file the content gets copied to the c file and this combination gets translated to a object file. So now the linker kicks in and combines multiple c files with multiple definitions of the same variable name to a binary file and gets confused, because there are multiple definitions of variables with the same name...see https://stackoverflow.com/questions/8108634/global-variables-in-header-filesimple solution, put a extern infront of your variables in the header...

simple solution, put a extern infront of your variables in the header...

And then get undefined references linker errors . Turning these definitions into declarations is only half the work, adding their definitions to the implementation the other half. A faster, better and more correct approach would be to move these variables into the class as members.

But anyway, these are very basic c/c++ errors because of lack of language knowledge and way off topic for this forum, better teach yourself c++ programming and head to a programming beginners forum.