Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

Linking in UNIX - again

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
slavikn
Asked:
slavikn
  • 5
  • 2
  • 2
  • +2
1 Solution
 
jinumjoyCommented:
do u include extern "C" macro??????

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

-Jinu
0
 
jinumjoyCommented:
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
 
slaviknAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Sjef BosmanGroupware ConsultantCommented:
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
 
slaviknAuthor Commented:
> 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
 
slaviknAuthor Commented:
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
 
slaviknAuthor Commented:
Stupid me... I didn't include all .o files in the "clean" clause in the makefile...  :'-(
0
 
x25Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
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
 
slaviknAuthor Commented:
> 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
 
CetusMODCommented:
Closed, 350 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now