954,193 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problems with a C program on different machines, using different compilers

Hi

I have Fedora Core 5 2.6.17-1.2174_FC5 with gcc version: gcc (GCC) 4.1.1 200
60525 (Red Hat 4.1.1-1)

everything compiles well, and run smoothly on my machine. But the actual production machine is Linux 2.4.20-46.9.legacysmp
with gcc version gcc (GCC) 3.2.2 20030222 ( Red Hat Linux 3.2.2-5)

on the production machine, I get errors like:
1) warning #266: function declared implicitly
while ((read = getline (&line, &len, sfile)) != -1) {

2) undefined reference to `sem_init'
3) undefined reference to `sem_destroy'

while I am using the correct headers:
#define _GNU_SOURCE
#include

for the getline

and
#include

for the sem_init and sem_destroy

I receive the same "warning #266: function declared implicitly" for my own defined functions as well, while my header is included,

any ideas where could be the problem,

sorry for asking a question that might be basic, but it is my first time to move code between different machines in linux and compilers versions,

I appreciate any help,

thanks,

Manal

mhelal
Newbie Poster
2 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

So if I understand corectly even you include your header files the compiler tells you that they are implicitly declared. That means that in first case they were also implicitly declared but the linker resolved the problems but with the second compiler the linker didn't resolved it. Always declare explicitly if U want to avoid these kind of problems.
Btw the getline is not C function and its not declared in stdio.h.

andor
Posting Whiz in Training
276 posts since Jun 2005
Reputation Points: 251
Solved Threads: 29
 

getline() in the posted example is probably his own C function because the parameters are incorrect for the c++ version. May I suggest you look in semaphore.h and see if there is a marco you need to define.

Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

thank you for your help,

No, I didn't declare a function called getline in my code, and I used it based on the manual as in:
http://www.die.net/doc/linux/man/man3/getline.3.html

and same about sem_init and sem_destroy, both are used according to:

http://www.die.net/doc/linux/man/man3/sem_init.3.html

and
http://www.die.net/doc/linux/man/man3/sem_destroy.3.html

and I can locate the semaphore.h on the machine, and the file contains the definitions:
extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value) __THROW;
extern int sem_destroy (sem_t *__sem) __THROW;

and my own defined functions, can now be located, sorry :)

Thank you again, I appreciate your help,

Manal

mhelal
Newbie Poster
2 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

hi..i have just installed turbo c++ software on my pc.And when i run a program then the output screen just blinks for a second and then disappears.Can please Suggest with the appropriate solution as soon as possible

swatithakur
Newbie Poster
1 post since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You