Author Topic: Code::Blocks doesn't seem to find .cpp files corresponding to .h files  (Read 13287 times)

Offline Mantrid

  • Single posting newcomer
  • *
  • Posts: 6
Hi everyone,

I have a minor problem with Code::Blocks. I want to include a library (pure code, no .lib or dlls), but Code::Blocks gives me Linker errors of unresolved external symbols. When I just copy all the code from the .cpp files in the .h files, everything works fine, so I guess Code::Blocks has a problem finding the .cpp files that correspond to the .h files, even though the names are the same, so test.cpp would correspond to test.h.

Any idea what I missed or what I have to do to make Code::Blocks find the .cpp files?

Best regards
Mantrid

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Mantrid

  • Single posting newcomer
  • *
  • Posts: 6
Thanks for the fast answer. Of course I did this before I was asking the question. None of those entries is related to my problem. I added all relevant paths, otherwise the library would not work when I copy the contents of the .cpp files in the .h files, because without the propper path in the compiler search directories, Code::Blocks does not find the header files at all. My question is rather like "How can I tell Code::Blocks that the functions corresponding to the prototypes in xyz.h are written in xyz.cpp, because it does not seem to figure that out by itself".

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Have you added all cpp files to the project?

If you have read and understood this faq entry: http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F you would have fixed you problem.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Mantrid

  • Single posting newcomer
  • *
  • Posts: 6
Of course I did not add the .cpp files of the library I want to use to my project....this would kind of defeat the whole purpose of a simple include of the header files.

And regarding your latter comment...look, if you have some kind of problem with people who have few posts or ask for help for the first time, let me give you a tip....nobody forces you to answer us ;)
Besides, I do understand the entry as well as the compiler output generated by my project, however I can't come up with an answer to my original question....if I could (by reading some FAQs or something else) I wouldn't be asking, because, frankly, I really dislike posting in forums....maybe because instead of getting an answer, one is just treated like an idiot...by people who probably doesn't have a clue either  ;D
« Last Edit: May 03, 2012, 03:36:46 pm by Mantrid »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
OK  ;D
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Mantrid

  • Single posting newcomer
  • *
  • Posts: 6
Great, so back to topic:

Other IDE automatically check for missing code in equally named .cpp files if not everything is included in a header file. How can I tell Code::Blocks to do this? Does anyone know this? Is it even possible? I mean I could just use the version of the library where I copied all the code from the .cpp files in the headers but it kind of feels wrong ^^

Thanks in advance,
Mantrid
« Last Edit: May 03, 2012, 03:56:20 pm by Mantrid »

Offline Freem

  • Almost regular
  • **
  • Posts: 219
I think I would create a static library. But this is only a workaround, if you really need to include cpp files...

Offline Radek

  • Multiple posting newcomer
  • *
  • Posts: 104
If I understand well, you have source code for a library and you want to use this library in your app. In fact, you would like something like a "source code library". You were able to smuggle the sources to your project by adding them to your INCLUDE path.

There is nothing like a "source code library" in C or C++. Either add the code to your project, perhaps indirectly (#include <source.cpp>), or build the library first. It the later case, you need 2 projects:

(1) The library. Add all sources belonging to the library to the project and create a static library. Once the library is created, it can be used in creating your apps.
(2) The app. Add source belonging to the app to the project and command the linker to link the project with your library.

Do not expect that some C or C++ IDE will search for your source code somewhere. C is a compiled language. "Source code libraries" can be found in interpreted or "network oriented" languages, like BASIC or Java.

Offline Mantrid

  • Single posting newcomer
  • *
  • Posts: 6
There is nothing like a "source code library" in C or C++. Either add the code to your project, perhaps indirectly (#include <source.cpp>), or build the library first.

I wasn't aware of that. Then I will go with the static library.

Thank you Radek and Freem :)


Ha....worked...great  :D
« Last Edit: May 03, 2012, 04:50:51 pm by Mantrid »

Offline Minerstrike

  • Single posting newcomer
  • *
  • Posts: 1
Re: Code::Blocks doesn't seem to find .cpp files corresponding to .h files
« Reply #10 on: August 08, 2022, 02:50:45 pm »
You probably created files as they are and tried to include them, in code blocks it seems you have to make a project first and add the files to the project thereafter