I am making some tutorial exercises for school practice in c. I have this little method(Heron's formula):
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
.
.
double s = (a+b+c)/2.0;
double A = sqrt(s*(s-a)*(s-b)*(s-c)) //a,b,c = 3,3,2
.
.
I can compile it with a gcc:
gcc exercise.c -o exercise -lm
Everything works well. Problem is, when i try to rewrite the same code in Netbeans, it throws this error:
/home/l2ysho/NetBeansProjects/cviko1/main.c:48: undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:62: recipe for target 'dist/Debug/GNU- Linux/cviko1' failed
make[2]: *** [dist/Debug/GNU-Linux/cviko1] Error 1
make[2]: Leaving directory '/home/l2ysho/NetBeansProjects/cviko1'
nbproject/Makefile-Debug.mk:59: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/home/l2ysho/NetBeansProjects/cviko1'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 861ms)
In Netbeans, sqrt() method only works with a number (sqrt(2.5)), but not with a constant (sqrt(s)). I think, it is some problem with a Netbeans compiler. Do anyone have some similar issue?
I found one solution. If you have the same problem, you can hard link a math.h in NetBeans IDE:
File->Project Properties->Build->Linker->Libraries->add Library/add standard Library
I also tried add an -lm argument to NetBeans compilator configuration, but this isn't worked.
Related
I am trying to run a C project "https://github.com/karimaechihabi/lernaean-hydra/tree/91b480fb633ab4730a2cf1f5573d20d55b39b71e/hydra1/code/ucr-suite", following the same steps to auto generate configuration and makefile as in the read me :
>./autogen.sh \
>./configure \
>make
But when i run make file, i got this error of undefined reference :
>usr/bin/x86_64-linux-gnu-ld: src/bin_serial-serial_scan.o: in function `main':
/home/zeraph/lernaean-hydra/hydra1/code/ucr-suite/src/serial_scan.c:143: undefined reference to `init_serial_stats'\
/usr/bin/x86_64-linux-gnu-ld: /home/zeraph/lernaean-hydra/hydra1/code/ucr-suite/src/serial_scan.c:147: undefined reference to `serial_scan'\
collect2: error: ld returned 1 exit status\
make[1]: *** [Makefile:486: bin/serial] Error 1\
make[1]: Leaving directory '/home/zeraph/lernaean-hydra/hydra1/code/ucr-suite'\
make: *** [Makefile:335: all] Error 2
Any Help Please ?
Ps : While runing the Configuration command to generate makefile, i also got this warning :
>/usr/share/automake-1.16/am/library.am: warning: 'lib/libserial.a': linking libraries using a non-POSIX \
/usr/share/automake-1.16/am/library.am: archiver requires 'AM_PROG_AR' in 'configure.ac'
The problems was with make dependencies(trying to build bin/serial before lib/libserial.a has been built);
Solution : first do make lib/libserial.a first, followed by make to build bin/serial.
I have to do a compiler with flex and bison for a school project.
They give to me example of new language but I can't compile them..
The code is working fine for other people so the problem come from my Mac. The problem appears when I try to compile with make command, he say "ld: library not found for -lglib-2.0".
I installed "Glib" already but this don't solve the problem.
make
[ 20%] Linking C executable facile
ld: library not found for -lglib-2.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [facile] Error 1
make[1]: *** [CMakeFiles/facile.dir/all] Error 2
make: *** [all] Error 2
I need to compile the code to work after on the project.
Thanks you
While compiling glibc 2.11, I get the following error. Any idea how to solve this.
In file included from ../sysdeps/unix/sysv/linux/syslog.c:10:
../misc/syslog.c: In function ‘__vsyslog_chk’:
../misc/syslog.c:123: sorry, unimplemented: inlining failed in call to ‘syslog’: function body not available
../misc/syslog.c:155: sorry, unimplemented: called from here
make[2]: *** [/home/alice/Desktop/glib-build/misc/syslog.o] Error 1
make[2]: Leaving directory `/home/alice/Desktop/glibc-2.11/misc'
make[1]: *** [misc/subdir_lib] Error 2
make[1]: Leaving directory `/home/alice/Desktop/glibc-2.11'
make: *** [all] Error 2
Apparently, this is a known problem with building glibc on Ubuntu. In essence:
glibc does not build with _FORTIFY_SOURCE enabled, and Ubuntu compiles stuff with -D_FORTIFY_SOURCE=2.
You need to disable this by undefining _FORTIFY_SOURCE. i.e. append -U_FORTIFY_SOURCE to your CFLAGS.
I added a third party library to my code and is getting errors like this when running make. Please help me understand this error.
(.text+0x9b4): undefined reference to `snd_strerror'
/home/bet/Tent/tun/app/Common/hl/lib/libGHAL.a(gfxhal.o): In function `GFX_create_region':
/home/bet/Tent/tun/app/Common/hl/src/GHAL/gfxhal.c:1141: undefined reference to `my_key_handler'
/home/bet/Tent/tun/app/Common/hal/src/GHAL/gfxhal.c:1141: undefined reference to `create_window'
collect2: ld returned 1 exit status
make[2]: *** [all] Error 1
make[2]: Leaving directory `/home/bet/Tent/tun/app/Common/c_app'
make[1]: *** [ctv_all] Error 2
make[1]: Leaving directory `/home/bet/Tent/tun/app/Common'
Those are Linking errors, which tell you the linker cannot find definitions for the library you are using.
You will have to link the library to your project.
gcc <your files for compilation> -lLibName
Read this for better understanding.
I still get the error even if
readline library is installed and
-lreadline is added to gcc compiling command.
The root cause of my issue is the order of the libraries/code: -lreadline (and other libraries) should be put right before -o options.
I am installing cminpack 1.1.2 on a clean install of Ubuntu 10.10.
When running sudo make in the cminpack folder, the folloing error occurs at 52%:
[ 52%] Building C object examples/CMakeFiles/genf77tests.dir/genf77tests.c.o
/usr/lib/cminpack-1.1.2/examples/genf77tests.c: In function ‘main’:
/usr/lib/cminpack-1.1.2/examples/genf77tests.c:44: warning: assignment makes pointer from integer without a cast
/usr/lib/cminpack-1.1.2/examples/genf77tests.c:86: warning: comparison between pointer and integer
Linking C executable genf77tests
CMakeFiles/genf77tests.dir/genf77tests.c.o: In function `main':
genf77tests.c:(.text+0xb5): undefined reference to `strnstr'
genf77tests.c:(.text+0x2a9): undefined reference to `strnstr'
collect2: ld returned 1 exit status
make[2]: *** [examples/genf77tests] Error 1
make[1]: *** [examples/CMakeFiles/genf77tests.dir/all] Error 2
make: *** [all] Error 2
I have looked inside genf77tests.c, and #include <string.h> is present, so I don't see why there is a problem finding strnstr.
Is there anything I can do to fix this issue?
strnstr is a non-standard function. Specifically, it is not included in Glibc. Whoever wrote genf77test.c did not test it on Linux/glibc...
strnstr is not standard C; as far as I can see, it's provided on the BSD UNIX family.
Still, if the only problem in your compilation is that one you can provide its prototype1 and add to the files to be compiled one that contains its implementation (for example this one).
Actually, you may not even need it: if the compilation gets to the linking stage and fails just there, you can solve throwing in just the implementation of strnstr.