I'm trying to compile a program with multiple source files - two CPP files and a header file, with code::blocks. As an example, I have created the following three files (an example program created by someone else on another forum):
main.cpp:
#include <stdio.h>
#include "other.h"
int main (void)
{
printf("%d\n", getfavoritenumber());
return 0;
}
other.cpp
#include "other.h"
int getfavoritenumber(void)
{
return 3;
}
other.h
#ifndef _OTHER_H_
#define _OTHER_H_
int getfavoritenumber(void);
#endif
Despite the fact that these three files should link to each other, I receive the error "Linking stage skipped (build target has no object files to link)" when I try to build the project.
What am I doing wrong? Trying to compile the individual files presents the error "That file isn't assigned to any target".
You can have multiple definitions of the same class in different files (or because you included the same header file in different source files), and C++ will check them all against each other to make sure that they are identical, and then will merge them into a single class definition in your program.
You can simply place a forward declaration of your second() function in your main. cpp above main() . If your second. cpp has more than one function and you want all of it in main() , put all the forward declarations of your functions in second.
Here is what worked for me:
Go to the left panel that says projects, and right-click on .cpp file. Select properties, then go to build. Check the boxes under the heading Belongs in Targets: "Debug" and "Release"
I had a similar problem when creating my first multi source code project. i believe the problem you are having is not with the linking but with you #include statement for me the directory's were different to what i expected. to include the header file in a project i had to write #include "include/other.h"
have a look at how your folder system is constructed....if you could post what folders/directory`s you have in the project i might be able to give you a better answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With