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:
warning #266: function declared implicitly while ((read = getline (&line, &len, sfile)) != -1) {
undefined reference to sem_init
undefined reference to sem_destroy

while I am using the correct headers

#define _GNU_SOURCE
#include <stdio.h>

for the getline

#include <semaphore.h>

for the sem_init and sem_destroy

I receive the same warning #266: function declared implicitlyfor 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,



Recommended Answers

All 4 Replies

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.

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.

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:

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



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,


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.