Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368938 - Wrong compilation errors
Summary: Wrong compilation errors
Status: CLOSED INVALID
Alias: None
Product: CDT
Classification: Tools
Component: cdt-other (show other bugs)
Version: 8.1.0   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Doug Schaefer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-18 06:27 EST by Germano Massullo CLA
Modified: 2012-02-23 11:30 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Germano Massullo CLA 2012-01-18 06:27:30 EST
Build Identifier: 8.0.0.201109151620

I was programming a very simple program using CDT 8.0 plugin in Eclipse, when at line
if(timer_create(_POSIX_MONOTONIC_CLOCK, &sigeventStruct, &numero1) == -1)
I got “undefined reference to `timer_create' ” error, so the compiling action stopped.
The flag of C compiler used in Eclipse are -O0 -g3 -Wall -c -fmessage-length=0 -lrt -std=gnu99

If you open bash and enter gcc timer.c -o prova -O0 -g3 -Wall -fmessage-length=0 -lrt -std=gnu99 it will work without errors, so the problem is Eclipse CDT.

Here down the full code example



#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>

int main()
{
        timer_t numero1;
        struct sigevent sigeventStruct;
        sigeventStruct.sigev_notify = SIGEV_SIGNAL;
        if(timer_create(_POSIX_MONOTONIC_CLOCK, &sigeventStruct, &numero1) == -1)
        {
                printf( "Errore: %s\n", strerror( errno ) );
        }
        for(int i = 0; i < 100; i++)
        {
        	printf("Test\n");
        	clearerr();
        }
        return 0;
}


Reproducible: Always

Steps to Reproduce:
1. Start a new C project.
2. Modify gcc flags by adding -lrt -std=gnu99
3. Compile
Comment 1 Germano Massullo CLA 2012-01-18 06:45:08 EST
Err, I forgot to delete the for cycle, please remove it from the code listing, or the example will not work
Comment 2 Marc-André Laperle CLA 2012-01-18 09:57:51 EST
Did you try adding the -rt flag to the linker settings? CDT compiles and links in two separate steps.
Comment 3 Germano Massullo CLA 2012-01-19 10:02:54 EST
> Did you try adding the -rt flag to the linker settings? CDT compiles and links
> in two separate steps.

Yes, now it works(In reply to comment #2)