Solved

borland 5.02 undefined symbol when using header files

Posted on 2011-02-25
15
683 Views
Last Modified: 2012-06-21
Hi,

I'm using borland 5.02 by creating a project of 16 bit (DOS standard) <== don't think what kind of project will make a difference with my problem but I need this to handle far pointers

anyway my problem is I included the header in my main program file of file1.cpp
using #include "file2.h"

the header file file2.h has a prototype of a function in file2.cpp

my problem is after I created a new project I added the file1.cpp to my project and have
the header file in the same folder as my file1.cpp file will do the trick

compiling goes fine without a problem
linking print the following message
"undefined symbol func() in module file1.cpp"

I don't understand I did include file2.h in my main program file1.cpp

can you please give me steps how to handle this
as I have tried to add header to project by using add node and then add the file2.h
but still didn't fix my problem, and also tried to add the file2.obj but also didn't fix my problem
can someone suggest a solution please...
0
Comment
Question by:logicallayer
  • 9
  • 5
15 Comments
 
LVL 45

Expert Comment

by:Kdo
ID: 34984101
Hi LL,

is func() declared [static]?  


Kent
0
 

Author Comment

by:logicallayer
ID: 34984286
No it's not...why?
0
 

Author Comment

by:logicallayer
ID: 34984298
Hi btw,
Just recognized you, thanks for dropping by :-D
0
 
LVL 4

Expert Comment

by:DanDauchy
ID: 34984617
Hello,

are you positive it worked when you just had file2.h and file2.cpp in the project?

if so, make sure that the function you're calling in file1.cpp matches the function prototyped in file2.h and defined in file2.cpp (parameters and all).
0
 

Author Comment

by:logicallayer
ID: 34985022
The problem is with the linker, some how my linker does see either my .obj or .lib but I don't know how to handle this
0
 
LVL 45

Expert Comment

by:Kdo
ID: 34985264
Hi LL,

Are you using the IDE, a makefile, or the command line?


Kent
0
 

Author Comment

by:logicallayer
ID: 34985276
I think that would be IDE
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:logicallayer
ID: 34985277
I think that would be IDE
0
 
LVL 45

Accepted Solution

by:
Kdo earned 250 total points
ID: 34985305
Ok.

If you're going to compile multiple files, you should define a project.  Project XXXXX will have a file XXXXX.prj.  This file includes the names of the files that need to be compiled and linked together.

Check to make sure that you have a project and that the IDE is using the project.  Then edit file XXXX.prj and make sure that all of the source files that you need to compile are in the .prj file.



Kent
0
 

Author Comment

by:logicallayer
ID: 34985382
If I incude more than one cpp file by using add node, what it does it says the var inside the header is already been defined before, im including the header more than one time in more than cpp file but im using
#ifndef _header
#define _header
Header content
#endif

You know what I mean, but still if I add all the cpp files to the project it says var been duplicated

I assumed I should include the main cpp file plus all the headers as they already have prototype of the function inside the other cpp files, am I right? Or I do have to include the other cpp files in the project as nodes s well?

0
 
LVL 45

Expert Comment

by:Kdo
ID: 34985407
Hi LL,

You only need the .c files.  They will expand out the .h files.

cpp files?  I wasn't aware of Borland having a 16-bit C++ IDE.


Kent
0
 

Assisted Solution

by:logicallayer
logicallayer earned 0 total points
ID: 34989140
it's embarrassing that although I have been programming for awhile, I havn't really used headers before. so I thought my including everything all your variables in the header it will be fine if you include that header in more than ".c" or ".cpp" file as long as you use
#ifndef
#ifdef
defentions
#endif

but I was wrong as you have to keep you variables inside the ".c" or ".cpp" file and if you want to share any of these variables with another ".cpp" file then you have to use an extern function in the header on top of the declaring the variables where you using them

that was my problem is when I included more than one .cpp file in a project it gave message of variables already decleared so I thought there was something wrong with the files I'm adding to the project but kdo is right I need to add all the ".cpp" or ".c" files to the project

I dunno kdo, my turboc 3.0 did use extension .cpp and I didn't really question why... weird I guess.

thanks for participation
0
 
LVL 45

Expert Comment

by:Kdo
ID: 34992052

Hi LL,

A word of caution.  If you're going to share variables, you'll be better served if the variables go into their own module.  Then you can declare a .h file that defines them as extern, and is common to ALL of the .c or .cpp files.  Otherwise you'll be declaring them as extern in all of the modules but the module where they are defined.  That can be a nuisance.  The early compilers often griped if you declared a variable in a module and also declared it extern in the same module.


Kent
0
 

Author Comment

by:logicallayer
ID: 35023913
I had to learn it the hard way, but you are totally right other wise as you said it can get too missy.

thanks kdo
0
 

Author Closing Comment

by:logicallayer
ID: 35025211
kdo was good, wasn't my problem but could be a solution for someone else having similar problem
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now