Undefined Reference when .h and .cpp files are in a source folder

Hello, I’m trying to continue building out my C++ project and organize it the way I like. That includes moving the .h and .cpp files in to a source folder called “src.”

Unfortunately, I’m no longer able to compile. I get this error:
undefined reference to PlayerCharacter::PlayerCharacter(int, int)`

How can I configure the project so that I can include .h files from the “src” folder in my main.cpp file?

Hi Michael,

The reason why this doesn’t work initially is because the project files are configured to only look for .h and .cpp files in the root of your project. However, there is a way to configure your project to look in folders.

In tasks.json, you want to change the line "OBJS=*.cpp", to "OBJS=$(wildcard *.cpp) $(wildcard */*.cpp)", for whichever operating system you’re using. Here’s an example where I setup a project to allow two levels of folders.

1 Like

That fixed it, thank you so much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms