Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Linking in UNIX - again

Posted on 2004-08-24
12
Medium Priority
?
242 Views
Last Modified: 2010-04-15
Hello,

When I compile:
g++ -Wall Memory.o MyStr.o LinkedList.o Ini.o DateTime.o Parse.o TestParse.o -o Main
it works.

When I compile:
g++ -Wall Memory.o MyStr.o LinkedList.o Ini.o DateTime.o Parse.o Main.o DataManagement.o -o Main
I get errors:
DataManagement.o: In function `FieldInit(Field **, first_node *, int)':
DataManagement.o(.text+0x301): undefined reference to `IniReadStr(first_node *, char *, char *, char *)'
DataManagement.o(.text+0x35d): undefined reference to `IniReadInt(first_node *, char *, char *, int)'
etc...

IniReadStr etc are implemented in Ini.o, so I cannot see the problem.
I also tried to put Ini.o after DataManagent.o, but it was no good.

The headers of some of the files are:

(DataManagement.h)

#ifndef INCLUDE_DATA_MANAGEMENT
#define INCLUDE_DATA_MANAGEMENT

#include "MyAssert.h"
#include "MyStr.h"
#include "Memory.h"
#include "LinkedList.h"
#include "Ini.h"
#include "DataBase.h"

(Main.c) - I don't have Main.h

#include <stdio.h>
#include "Parse.h"
#include "Ini.h"
#include "DataManagement.h"
#include <stdlib.h>
#include <unistd.h>
#include "DataBase.h"
#include "MyAssert.h"
#include "MyStr.h"

(Ini.h)

#ifndef _DEF_INI__FILE
#define _DEF_INI__FILE

#include <stdio.h>
#include "LinkedList.h"

--------------------------------------------------------

All the files are written in C, except MyStr which is written in C++. However as you can see, the first example (g++ -Wall Memory.o MyStr.o LinkedList.o Ini.o DateTime.o Parse.o TestParse.o -o Main) works perfectly well, so I don't think the problem is there...

Please help.
Thanks in advance.
0
Comment
Question by:slavikn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +2
12 Comments
 

Expert Comment

by:jinumjoy
ID: 11889244
do u include extern "C" macro??????

search for this.. this should help you out!!!!

-Jinu
0
 

Expert Comment

by:jinumjoy
ID: 11889257
I hope u do have function prototypes for functions u call outside the current file!

For example when IniReadStr(first_node *, char *, char *, char *) is called from DataManagement.c does it have prototype of the functions ( can be included from a header .h ) which is implemented in Ini.c?

also when u r making calls to C functions from C++ code use extern "C"  ( do google around for it )

-Jinu
0
 
LVL 1

Author Comment

by:slavikn
ID: 11890189
extern "C" doesn't help. please refer to http://www.experts-exchange.com/Programming/Programming_Languages/C/Q_21104444.html#11876848

Yes, all functions are accessible from all files I need, and are included in the respective .h files.

It's just that it's not:
IniReadStr(first_node *, char *, char *, char *)
but
char * IniReadStr (Ini * ini, char * sec, char * key,char * def);
(same for int)

first_node replaced Ini because I have:
typedef LinkedList Ini;
in Ini.h
and in LinkedList.h I have:
typedef struct first_node {
      Node * head;
      Node * tail;
        int lenght;
} LinkedList;

Apart from that, all files (including DataManagement include "Ini.h" (and "LinkedList.h" for other uses), so I don't know why the problem occurs...

-------------------------------------------------------

As you can see, the problem occurs when I replace "TestParse.o" by "Main.o DataManagement.o"

Maybe this help:

nova 4% less TestParse.c              <--- I don't have TestParse.h
#include <stdio.h>
#include "Parse.h"
#include "MyAssert.h"

int main(void)
{
   ...
}

-----

nova 6% less Main.c              <--- I don't have Main.h
#include <stdio.h>
#include "Parse.h"
#include "Ini.h"
#include "DataManagement.h"
#include <stdlib.h>
#include <unistd.h>
#include "DataBase.h"
//#include "PerformDbTask.h"
#include "MyAssert.h"
#include "MyStr.h"

int main (int argc, char * argv[])
{
   ...
}

--------------------

nova 9% less DataManagement.h

#ifndef INCLUDE_DATA_MANAGEMENT
#define INCLUDE_DATA_MANAGEMENT

#include "MyAssert.h"
#include "MyStr.h"
#include "Memory.h"
#include "LinkedList.h"
#include "Ini.h"
#include "DataBase.h"
+ function declarations

nova 10% less DataManagement.c
#include "DataManagement.h"
+internal macros
+functions

-----------------------------------

The only C++ file is MyStr.cpp & MyStr.h
They don't use any of the project's files.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11897258
But then, since you effectively use the g++ C++ linking methods, both IniReadStr functions are different. Either use a union or cast to get the type of ini right.
0
 
LVL 1

Author Comment

by:slavikn
ID: 11897380
> Both IniReadStr functions are different.
I don't understand what you mean...
I have only one IniReadStr function.
The other one is IniReadInt.

Please explain yourself.
0
 
LVL 1

Author Comment

by:slavikn
ID: 11897531
The problem was solved.
I just had to remove all my old .o files.
Don't know why "clean" didn't do the job...
Thanks anyway.
0
 
LVL 1

Author Comment

by:slavikn
ID: 11897582
Stupid me... I didn't include all .o files in the "clean" clause in the makefile...  :'-(
0
 

Expert Comment

by:x25
ID: 11899807
This is not an objective, but rather a comment to sjef_bosman:
The function prototype:
<code>
IniReadStr(first_node *, char *, char *, char *);
</code>
is exactly the same for this one:
<code> char * IniReadStr (Ini * ini, char * sec, char * key,char * def);  </code>
with respect to slavikn's description about `Ini'.
(With a small exception on the return value; but i am assuming slavikn just forgot to include that part in the comment)

P.S.
GNU make should have updated the .o files for you accordingly, regardless of any earlier cleanups.
Or else, you must be using an obsolete makefile format.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 11900192
It was just a long shot of my part, sorry to have mislead anybody. As you see, my C++ experience is less than adequate to answer questions, so you won't find me in that TA. Thanks for correcting me!

Sjef :)

PS No comments as to closing this question.
0
 
LVL 1

Author Comment

by:slavikn
ID: 11900525
> but i am assuming slavikn just forgot to include that part in the comment

oops... sorry for that. you are right. the return value is also identical
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11988847
Closed, 350 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

730 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