Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans-specific C++ error "Undefined reference to XXX" - (Solution posted)

Tags:

c++

netbeans

I wrangled with this problem for a good 5 or 6 hours, pulling my hair out until I finally found a solution. I wanted to post this (not sure if there is a specific place to post solutions to unasked questions) as a solution for others who may run into the same difficulty.

I am coding a C++ project in Netbeans 7.1.1 running on Linux Mint Lisa, and kept on getting an "Undefined reference to XXX" error when trying to use a static variable. Coming from a background in C# and thus not very familiar with header files and the like, I searched for hours expecting to find a problem with the way I declared my variable or my class. I couldn't find anything...

like image 999
Levi Botelho Avatar asked Apr 18 '12 21:04

Levi Botelho


2 Answers

Go to your nbproject folder in the files explorer in Netbeans. Open up the configurations.xml file. Scroll down to the logicalFolder tag with the attribute name="SourceFiles". Make sure that all your .h and .cpp files are included as itemPath tags within the logicalFolder tag! Netbeans correctly added some, but not all of my cpp and h files, hence the problem. Not sure why there would be this inconsistency, as all class and header files were added through the same Netbeans wizard. Anyways, with the configurations file changed, the makefiles were then updated and written correctly on the next build and all functioned as expected. Hope this can help somebody!

like image 111
Levi Botelho Avatar answered Oct 18 '22 12:10

Levi Botelho


Just to add more details to Levi's answer (for anyone newish to this like me), click the "Files" tab on the left of the screen, where your list of files and folders is. This gives you a different list of files than the "Project" tab does.

Expand your project folder if it isn't expanded already. One of the resulting folders is "nbproject." Expand the folder. This is where configurations.xml is.

In short:

Files tab > nbproject > configuration.xml

However, adding the .h files to configuration.xml did not work for me.

like image 20
user124384 Avatar answered Oct 18 '22 12:10

user124384