"undefined reference to `strnstr'" when installing cminpack - c

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.

Related

Undefined reference to main error very persistent

I'm using the Eclipse Oxygen IDE on Linux, and I am trying to code in C. There are some problems though.
Whatever code I try to build, even perfectly valid code, returns this error:
make all
Building target: heyson
Invoking: GCC C Linker
gcc -o "heyson" ./heyson.o
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
makefile:29: recipe for target 'heyson' failed
collect2: error: ld returned 1 exit status
make: *** [heyson] Error 1
This is all of my code:
#include <stdio.h>
int main(){
printf("hello");
return 0;
}
It's literally a hello-world program. I tried putting main(void), but that returned the same error, I tried removing the #include line but that kept it the same, I did nigh everything possible to this and it keeps spitting out the same thing.
All I did, was install the C/C++ version of eclipse, use the Linux GCC toolchain to create a project, create a source file called heyson.c, and put this code in, trying to build it. After some time I realised that everything I put in returned the same thing, so I'm at the point of desperation...
UPDATE: I decided to uninstall Eclipse and use CLion instead. It works brilliantly, so I can only conclude that the problem was the IDE itself.

Error when compiling file | collect2: error: ld returned 1 exit status

I am having a lot of problem and can't seem to make any sense of what is going on. I am trying to learn C from Learn C The Hard Way, and I am trying to compile the first exercise. When ever I run make I get a huge problem
cc ex1.c -o ex1
ex1.c: In function ‘main’:
ex1.c:3:5: warning: implicit declaration of function ‘put’ [-Wimplicit-function-declaration]
put("Hello world.");
^
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/5.3.1/../../../libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /lib/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/libc.so when searching for -lc
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'ex1' failed
make: *** [ex1] Error 1
any help would be wonderful
The first error is clear; there is no declaration for a function called put(). This is either because
you have mistyped the function name,
or because you have failed to provide a declaration either directly of via a header file containing the declaration.
In this case if the code you were attempting to compile is from this exercise then look at it again - it clearly differs from your code (i.e. the first of the possibilities listed above). However even then you would get the same error; read further in the exercise and you will see that the author has deliberately omitted the header file in order to illustrate the need for the specific library header file. The reason you get the warning without the suggested -Wall command line option is probably because you are using a newer version of the compiler than the author. To be honest from what little I have seen of "Learn C the Hard Way", I would steer clear of it.
The second issue is one of your linker being unable to find an appropriate version of the standard C library to link to your code. Compiling C code in Linux is normally straightforward; most distributions come with GCC already correctly installed and working; your's appears to be horribly broken. You may want to repair your toolchain installation. You may have installed multiple incompatible toolchains.

OpenGL Compilation Errors Ubuntu

I'm trying to set up the code from
http://www.openglsuperbible.com/example-code/
with command:
$ cmake -G "Unix Makefiles" ; make clean ; make all
I've installed the following packages in order to prepare the system:
xrandr libxrandr x11-xserver-utils libxrandr-dev libglfw2 libglfw-dev xorg-dev libx11-dev libgl-dev libglu-dev libgl1-mesa-dev freeglut3 freeglut3-dev mesa-common-dev freeglut3-dev build-essential libx11-dev libx11-*
I may have missed some of the packages I've installed in this list, I apologize.
Then I've modified the CMakeList.txt in order to add to the linking phase the following things:
glfw GL rt glut X11 dl Xrandr Xext GLEW GLU
Then I try to compile, but it fails at the linking phase:
/opt/sb6code/src/xraw/xraw.c: In function ‘CreateWindow’:
/opt/sb6code/src/xraw/xraw.c:106:14: warning: assignment makes pointer from integer without a cast [enabled by default]
Linking C executable bin/xraw
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XOpenDisplay'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCloseDisplay'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCreateColormap'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XCreateWindow'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'XMapWindow'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'glXCreateContextAttribsARB'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function Cleanup: error: undefined reference to 'XDestroyWindow'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function Cleanup: error: undefined reference to 'XCloseDisplay'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function main: error: undefined reference to 'XNextEvent'
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function main: error: undefined reference to 'XGetWindowAttributes'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/xraw] Errore 1
make[1]: *** [CMakeFiles/xraw.dir/all] Errore 2
make: *** [all] Errore 2
Now, I've tried to search the web and even here on SO.com for solutions, but they keep telling me to link the libraries I've already added to the linking phase.. so I can't seem to make any more progress.
Do you happen to have some knowledge or hint that could help me?
Ok, stimulated by answers I've gone into CMakeFiles directory and looked for the configuration file that manages the compilation. I've found out that for some reasons it did miss some of the flags stated into the CMakeLists despite of my update.
So now the compilation line looks like:
/usr/bin/cc CMakeFiles/xraw.dir/src/xraw/xraw.c.o -o bin/xraw -L/opt/sb6code/lib -rdynamic -lGL -lglut -lGLU -lm -lX11 -ldl -lGLEW -lXrandr -lXext -lrt -lglfw -Wl,-rpath,/opt/sb6code/lib
And the errors have reduced to :
CMakeFiles/xraw.dir/src/xraw/xraw.c.o:xraw.c:function CreateWindow: error: undefined reference to 'glXCreateContextAttribsARB'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/xraw] Errore 1
make[1]: *** [CMakeFiles/xraw.dir/all] Errore 2
make: *** [all] Errore 2
Other hints? :)
Side Note:
I've also installed CUDA libraries and under path
/usr/lib/nvidia-304/
I happen to have
alt_ld.so.conf libnvidia-ml.so.1
bin/ libnvidia-ml.so.304.88
ld.so.conf libnvidia-opencl.so.1
libcuda.so libnvidia-opencl.so.304.88
libcuda.so.1 libnvidia-tls.so.304.88
libcuda.so.304.88 libnvidia-wfb.so.1
libGL.so libnvidia-wfb.so.304.88
libGL.so.1 libOpenCL.so
libGL.so.304.88 libOpenCL.so.1
libnvcuvid.so libOpenCL.so.1.0
libnvcuvid.so.1 libOpenCL.so.1.0.0
libnvcuvid.so.304.88 libXvMCNVIDIA_dynamic.so.1
libnvidia-cfg.so libXvMCNVIDIA.so
libnvidia-cfg.so.1 libXvMCNVIDIA.so.1
libnvidia-cfg.so.304.88 libXvMCNVIDIA.so.304.88
libnvidia-compiler.so tls/
libnvidia-compiler.so.1 vdpau/
libnvidia-compiler.so.304.88 xorg/
libnvidia-glcore.so.304.88 XvMCConfig
libnvidia-ml.so
Which I would like to use since I'm not sure that my intel graphic card supports OpenGl 4.* which I shall use with the book, while the nvidia one supports 4.2.
I really can't find any good how to on the matter, the Book conveniently avoids to give installation instructions.
Temporary Solution:
I've found out that this is the only source file that does not work. Removing its files and CMakeList.txt configuration seems to be wise until someone finds out another solution.
Also, i had to use optirun to run the executables, in case other people with bumblebee/nvidia are wondering why their programs do not work.
You probably link the libraries in wrong order; all these symbols are defined in libX11.a; you should want to see what is the actual linking command line fed to GCC, and post it here.
Update now it means that you are statically trying to link against an API function that is not available in your libs (it is an optional extension and should be queried dynamically).

undefined reference to `ceilf'

I am trying to "make" a program and yet face these errors; I used make -lm and even did #include but still I face the same problem. I tried installing the application on both Ubuntu and Debian just to make sure I remove doubts on corrupted libraries.Still no success !
nat_src_endpoint_ip.o: In function `__new':
/root/softwares/sweetspot-0.0.20/src/nat_src_endpoint_ip.c:95: undefined reference to `ceilf'
nat_src_endpoint_tcp.o: In function `__create':
/root/softwares/sweetspot-0.0.20/src/nat_src_endpoint_tcp.c:58: undefined reference to `ceilf'
nat_src_endpoint_udp.o: In function `__create':
/root/softwares/sweetspot-0.0.20/src/nat_src_endpoint_udp.c:59: undefined reference to `ceilf'
nat_src_endpoint_icmp.o: In function `__create':
/root/softwares/sweetspot-0.0.20/src/nat_src_endpoint_icmp.c:48: undefined reference to `ceilf'
collect2: ld returned 1 exit status
make[1]: *** [sweetspot] Error 1
make[1]: Leaving directory `/root/softwares/sweetspot-0.0.20/src'
make: *** [all] Error 2
You should link with the math library. In Gcc this means that you should add -lm to the linking command line (if you only use one command line it means that this command line is both for compiling and linking).

'undefined reference' errors when compiling against library

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.

Resources