You are not logged in.
My source code:
#include <stdio.h>
#include <math.h>
int main(void) {
float x, y;
y = 5;
x = log(y);
printf("%f\n", x);
return 0;
}
Running GCC:
bash-3.2# gcc -o /usr/bin/testlog /home/karam/testlog.c
/tmp/ccC4o2tO.o: In function `main':
testlog.c:(.text+0x19): undefined reference to `log'
collect2: ld returned 1 exit status
Running GCC with the verbose tag:
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,treelang --enable-threads=posix --mandir=/usr/share/man --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic
Thread model: posix
gcc version 4.3.0 (GCC)
COLLECT_GCC_OPTIONS='-o' '/usr/bin/testlog' '-v' '-mtune=generic'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/cc1 -quiet -v /home/karam/testlog.c -quiet -dumpbase testlog.c -mtune=generic -auxbase testlog -version -o /tmp/cccPgY2e.s
ignoring nonexistent directory "/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/include
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/include-fixed
/usr/include
End of search list.
GNU C (GCC) version 4.3.0 (x86_64-unknown-linux-gnu)
compiled by GNU C version 4.3.0, GMP version 4.2.2, MPFR version 2.3.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f09caaaff33a7d24655f4bdc6a5a8cad
COLLECT_GCC_OPTIONS='-o' '/usr/bin/testlog' '-v' '-mtune=generic'
as -V -Qy -o /tmp/ccuax4mo.o /tmp/cccPgY2e.s
GNU assembler version 2.18 (x86_64-unknown-linux-gnu) using BFD version (GNU Binutils) 2.18
COMPILER_PATH=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-o' '/usr/bin/testlog' '-v' '-mtune=generic'
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/collect2 --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib/ld-linux-x86-64.so.2 -o /usr/bin/testlog /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../lib/crt1.o /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../lib/crti.o /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/crtbegin.o -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0 -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0 -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../.. /tmp/ccuax4mo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/crtend.o /usr/lib/gcc/x86_64-unknown-linux-gnu/4.3.0/../../../../lib/crtn.o
/tmp/ccuax4mo.o: In function `main':
testlog.c:(.text+0x19): undefined reference to `log'
collect2: ld returned 1 exit status
Last edited by tony5429 (2008-04-26 14:45:30)
Offline
You also need to tell gcc to link with the math library.
gcc -o /usr/bin/testlog /home/karam/testlog.c -lm
Last edited by winch (2008-04-21 19:06:41)
Offline
It worked; thanks!
Offline
The -lm flag works, but is there I way to let gcc do it automatically? I use Vim and gcc manually at home, but my professor wants us to use Netbeans in class, and it won't compile because of that.
Offline
The -lm flag works, but is there I way to let gcc do it automatically? I use Vim and gcc manually at home, but my professor wants us to use Netbeans in class, and it won't compile because of that.
You mean it won't link.
No. GCC doesn't have a crystal ball to guess which libraries you need.
Offline
Why not? Why isn't #include <math.h> good enough?
Offline
The -lm flag works, but is there I way to let gcc do it automatically? I use Vim and gcc manually at home, but my professor wants us to use Netbeans in class, and it won't compile because of that.
Can use make? So can generate a simple Makefile
Offline
I find it hard to believe that Netbeans wouldn't have a method of defining linker arguments, have you looked around for something like that?
Offline
Why not? Why isn't #include <math.h> good enough?
For building but not for linking.
Offline
lol I just got this error today! Use -lm for linking: 'gcc allyourobjfiles.o -o exefile -lm'
urxvtc / wmii / zsh / configs / onebluecat.net
Arch will not hold your hand
Offline
.
Last edited by fumbles (2020-09-26 11:44:03)
Offline
g_SG wrote:The -lm flag works, but is there I way to let gcc do it automatically? I use Vim and gcc manually at home, but my professor wants us to use Netbeans in class, and it won't compile because of that.
Can use make? So can generate a simple Makefile
True! That's so obvious I'm ashame I didn't think about it. Thanks!
Offline