slavikn
asked on
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+0x3 01): undefined reference to `IniReadStr(first_node *, char *, char *, char *)'
DataManagement.o(.text+0x3 5d): 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.
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+0x3
DataManagement.o(.text+0x3
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.
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
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
ASKER
extern "C" doesn't help. please refer to https://www.experts-exchange.com/questions/21104444/Linking-in-UNIX.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.
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.
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.
ASKER
> 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.
I don't understand what you mean...
I have only one IniReadStr function.
The other one is IniReadInt.
Please explain yourself.
ASKER
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.
I just had to remove all my old .o files.
Don't know why "clean" didn't do the job...
Thanks anyway.
ASKER
Stupid me... I didn't include all .o files in the "clean" clause in the makefile... :'-(
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.
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.
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.
Sjef :)
PS No comments as to closing this question.
ASKER
> 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
oops... sorry for that. you are right. the return value is also identical
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
search for this.. this should help you out!!!!
-Jinu