Author Topic: linking multiple source files to .h  (Read 2511 times)

Offline kingcode

  • Single posting newcomer
  • *
  • Posts: 2
linking multiple source files to .h
« on: December 07, 2012, 03:18:31 am »
I have a project with 4 files, ALL of which are stored in the same directory:
main.cpp
test.cpp
test1.cpp
test.h

test and test1 each define functions for two classes declared in test.h (class test and class test1 for example).
All source files contain: #include "test.h"
main, test, and test.h all work properly, but when I added test1, I got an error:

test1 var;
var.function();

error - 'var' was not declared in this scope

however, the object test1 var was successfully created.
This leads me to believe test1 has not been linked to the .h
Does something additional need to be done to link source files, even if they are already in the project?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7607
    • My Best Post
Re: linking multiple source files to .h
« Reply #1 on: December 07, 2012, 05:28:59 am »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline kingcode

  • Single posting newcomer
  • *
  • Posts: 2
Re: linking multiple source files to .h
« Reply #2 on: December 07, 2012, 02:37:14 pm »
Hi, sorry for not explaining my problem clearly.  I've already read those two links, but my problem wasn't specifically answered there.

I've been using a different IDE up until now, in which you update the makefile when adding additional files to a project.  I'm new to code blocks, and was under the impression that makefiles are not used, and new files are linked automatically.
I'm just trying to figure out what the process is for linking additional files to the project.  Simply adding them to the project doesn't seem to be successful.
I just included the code examples for a little background.

Thanks for the follow up.

« Last Edit: December 07, 2012, 03:22:42 pm by kingcode »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7607
    • My Best Post
Re: linking multiple source files to .h
« Reply #3 on: December 07, 2012, 10:43:32 pm »
You do realize that no normal compiler/linker links header files.

I still have no idea what your problem is about.

Tim S.
« Last Edit: December 07, 2012, 10:51:08 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org