Solved

Linking in UNIX - again

Posted on 2004-08-24
12
222 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
  • 5
  • 2
  • 2
  • +2
12 Comments
 

Expert Comment

by:jinumjoy
Comment Utility
do u include extern "C" macro??????

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

-Jinu
0
 

Expert Comment

by:jinumjoy
Comment Utility
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
Comment Utility
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
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
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
Comment Utility
> 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:slavikn
Comment Utility
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
Comment Utility
Stupid me... I didn't include all .o files in the "clean" clause in the makefile...  :'-(
0
 

Expert Comment

by:x25
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
Closed, 350 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Adjust Mfcapp 29 154
C dll call freezes 5 88
Socket Programming (Unix) 8 98
Global Keyboard Hooks Blocked 4 55
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

744 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