Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

384
Views
undefined reference to conj, conjf, conjl

I cannot figure out how to fix this linking problem in GCC.
I am running CodeBlocks 13.12, under Windows 8, GCC+MingWG 4.8.1.
I have created a project having two files:

main.c

#include <complex.h>
int main(void)  
{  
    double complex (*FUNC)(double complex) = conj;   
    return 0;  
}  

test.c

#include <complex.h>  
double complex (*CEXP)(double complex) = cexp;  
double complex (*CONJ)(double complex) = conj;  

When the project is compiled in CodeBlocks (I use the compiler option -std=c11, only),
an error results, saying: "Undefined reference to conj".

I think this is extrange, since the function conj is defined in complex.h, as function cexp is, but the reference to cexp seems to work well.

On the other hand, the error is not triggered for the reference to conj in file main.c.
(SORRY: It seems that the error is triggered in main.c, also)

Is this a particular issue of GCC?
How I must configure CodeBlocks to fix this problem?
Thanks in advance.

More information. The compiler window shows these lines in CodeBlocks:

mingw32-gcc.exe -Wall -g -std=c11 -g -std=c11 -c C:\Users\Machine\Desktop\myapp\myapp.c -o obj\Debug\myapp.o
mingw32-gcc.exe -Wall -g -std=c11 -g -std=c11 -c C:\Users\Machine\Desktop\myapp\test.c -o obj\Debug\test.o
mingw32-g++.exe -o bin\Debug\myapp.exe obj\Debug\myapp.o obj\Debug\test.o
obj\Debug\myapp.o: In function main': C:/Users/Machine/Desktop/myapp/myapp.c:9: undefined reference toconj' obj\Debug\test.o:test.c:(.data+0x4): undefined reference to `conj' collect2.exe: error: ld returned 1 exit status

ALSO: I've tried to write the option -lm in several places on CodeBlocks without any success (for example, in Settings/Compiler/Other options, or Settings/Compiler/Linker, or Project/Build options..., etc.).

MOREOVER: The function conj is defined as "inline" by MinGW32 in complex.h. I souspect that this could be the problem, but using option -fno-inline has not any effect.

NM program: By following the suggestion of o11c, I used the nm program. The following output is obtained:

<snip, not what was needed>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Okay, I think I see where your problem is now; you are trying to take the entry-point addresses of conj() and cexp(), which works for cexp(), but not for conj(). The explanation is that cexp() is a real external function, for which you can obtain an address, but, if you are using a mingwrt-3.x predating mingwrt-3.21, (or any broken, and now withdrawn mingwrt-4.x release), conj() is implemented as __inline__, with no corresponding external implementation, so there is no way to get its address.

I've fixed this issue, in mingwrt-3.21, so you should ensure that you are using that, (preferably the mingwrt-3.21.1 release).

over 4 years ago · Santiago Trujillo Report

0

I turned my comment on Keith Marshall's answer into an answer as well (as it's too long for a comment):

As per Keith Marshall's answer, the problem is that they are inline, and that gcc is not producing a non-inlined version.

To get around this, add

static double complex conj_ (double complex a)
{
    return conj (a);
}

etc. - you can take the addresses of these, and if ever conj becomes non-inline, the function should optimise out to a simple address of conj.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!