LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-09-2008, 05:27 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Rep: Reputation: 32
problem with include files...


Hello,

I have this files:

main.c
global.h
tc1_task/tc1_task1.c
tc1_task/tc1_task2.c
tc1_task/tc1_task3.c

well, in global.h file I have all my global varibales, and I would like to use in all my task.
But if I make include in all .c files I have the follow error:

main.c:23: multiple definition of `signum'
tc1_task/tc1_task1.c:23: multiple definition of `signum'
tc1_task/tc1_task2.c:23: multiple definition of `signum'
tc1_task/tc1_task4.c:23: multiple definition of `signum'

By other hand I put include file only in main.c file and the other files I declarate all my variables as extern. It works but not with all of them.
For example:

in global.h

typedef struct{
unsigned int contador;
}SHARED_DATA_typ;

SHARED_DATA_typ *shared_data;

And now I would like to use this struct in tc1_task/tc1_task1.c, and I put :

extern SHARED_DATA_typ *shared_data;

it does not work.

any advice????

Best regards
 
Old 07-09-2008, 06:07 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Yes - look at any real program out there, or even the GCC headers or kernel headers. They all use the same precompiler trick:

#ifndef FILE_NAME_H
#define FILE_NAME_H

... all declarations

#endif /* FILE_NAME_H */
 
Old 07-09-2008, 06:29 AM   #3
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by pinniped View Post
Yes - look at any real program out there, or even the GCC headers or kernel headers. They all use the same precompiler trick:

#ifndef FILE_NAME_H
#define FILE_NAME_H

... all declarations

#endif /* FILE_NAME_H */
Thanks a lot pinniped,

I have started to use linux two months ago, and it is very hard to understand.

best regards
John
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
X include files mgreen Linux - Software 1 03-03-2008 05:31 AM
X include files Gonto Linux - Software 8 01-22-2006 03:42 AM
Problem with C++ include/header files! Pisces107 Programming 12 12-23-2003 11:06 PM
X include files evian Linux - General 6 03-25-2003 03:53 PM
*.h files....where to put them for #include centr0 Programming 7 03-13-2003 06:26 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration