Sqlite amalgamation C file doesn't compile on Raspbian - c

I am using a Raspberry Pi to run a C program that interacts with a can interface, and stores values in a database as part of a project.
I started C one month ago, and I am still a bit lost with everything.
Description of my workspace and problem :
I have my test file test virtual.c that includes a homemade file handler_code.c that includes the sqlite3.c amalgamation file(via #include "sqlite3.c").
Then I have a CMakeLists.txt that was provided to me :
if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
set( STANDALONE TRUE )
cmake_minimum_required(VERSION 3.13)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(CARLOS REQUIRED)
else()
include_directories(${CMAKE_SOURCE_DIR}/core/include)
include_directories(${CMAKE_BINARY_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/gui/include)
endif()
add_definitions(-DRESOURCES_DIR="${CMAKE_CURRENT_SOURCE_DIR}/resources")
add_executable(test_example "test virtual.c")
target_link_libraries(test_example carlos)
set_target_properties(
test_example
PROPERTIES
C_STANDARD 99
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/examples_bin
)
It imports all libraries I need. All the files are in the same directory.
I then go in the subdirectory build and run cmake .. which succeeds and then make. This is what happens :
pi#raspberrypi:~/Desktop/examples/build $ make
[ 50%] Building C object CMakeFiles/test_example.dir/test_virtual.c.o
In file included from /home/pi/Desktop/examples/handler_code.c:5,
from /home/pi/Desktop/examples/test virtual.c:8:
/home/pi/Desktop/examples/sqlite3.c:34058:42: error: ‘mremap’ undeclared here (not in a function); did you mean ‘munmap’?
{ "mremap", (sqlite3_syscall_ptr)mremap, 0 },
^~~~~~
munmap
/home/pi/Desktop/examples/sqlite3.c: In function ‘unixRemapfile’:
/home/pi/Desktop/examples/sqlite3.c:38625:42: error: ‘MREMAP_MAYMOVE’ undeclared (first use in this function)
pNew = osMremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
^~~~~~~~~~~~~~
/home/pi/Desktop/examples/sqlite3.c:38625:42: note: each undeclared identifier is reported only once for each function it appears in
/home/pi/Desktop/examples/sqlite3.c:38625:42: warning: passing argument 4 of ‘(void * (*)(void *, size_t, size_t, int, ...))aSyscall[24].pCurrent’ makes integer from pointer without a cast [-Wint-conversion]
/home/pi/Desktop/examples/sqlite3.c:38625:42: note: expected ‘int’ but argument is of type ‘struct unix_syscall *’
make[2]: *** [CMakeFiles/test_example.dir/build.make:63: CMakeFiles/test_example.dir/test_virtual.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/test_example.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I tried only compiling sqlite3.c with gcc and I got this :
pi#raspberrypi:~/Desktop/examples $ gcc sqlite3.c
/usr/bin/ld: /usr/lib/gcc/arm-linux-gnueabihf/8/../../../arm-linux-gnueabihf/crt1.o: in function `_start':
(.text+0x34): undefined reference to `main'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `pthreadMutexAlloc':
sqlite3.c:(.text+0x5098): undefined reference to `pthread_mutexattr_init'
/usr/bin/ld: sqlite3.c:(.text+0x50a8): undefined reference to `pthread_mutexattr_settype'
/usr/bin/ld: sqlite3.c:(.text+0x50c8): undefined reference to `pthread_mutexattr_destroy'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `pthreadMutexTry':
sqlite3.c:(.text+0x51b8): undefined reference to `pthread_mutex_trylock'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `sqlite3ThreadCreate':
sqlite3.c:(.text+0x9fcc): undefined reference to `pthread_create'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `sqlite3ThreadJoin':
sqlite3.c:(.text+0xa084): undefined reference to `pthread_join'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `unixDlOpen':
sqlite3.c:(.text+0x148c0): undefined reference to `dlopen'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `unixDlError':
sqlite3.c:(.text+0x148f4): undefined reference to `dlerror'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `unixDlSym':
sqlite3.c:(.text+0x14970): undefined reference to `dlsym'
/usr/bin/ld: /tmp/cc6Quw7S.o: in function `unixDlClose':
sqlite3.c:(.text+0x1498c): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
I also did some tests on my windows computer. The file named config.c includes the amalgamation just like handler_code.c did.
PS C:\Users\p107770\Desktop\projects\hmi-rapid-prototyping\C> gcc sqlite3.c
C:/MATLAB/V_R2016b/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
C:/crossdev/src/mingw-w64-v3-git/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
PS C:\Users\p107770\Desktop\projects\hmi-rapid-prototyping\C> gcc config.c
PS C:\Users\p107770\Desktop\projects\hmi-rapid-prototyping\C>
So here, it successfully compiles the file that includes the amalgamation file (which is what I'd want on my raspberry pi, even though it's not the same file), but it does not compile the amalgamation file alone (which I don't understand).
Ideas I found while searching
Using sqlite as a library/package in CMake file
Something looking like this. But looking at my CMake file, I realized that my sqlite amalgamation file was not a "package" in the same way CARLOS and Threads are (I installed CARLOS with .deb files provided to me). So my question here is how to transform the amalgamtion file into a package ?
Compiling sqlite so it would be imported globally
I remember reading something about this. If I recall correctly, I can compile the sqlite amalgamation file into a .dll and make it available in any C file with the #include <sqlite3.c> line instead of #include "sqlite3.c", but I don't know if it would work here because I think this was working when compiling with gcc and not with make.
Thank you in advance for any help you could bring, I can add bits of code if needed.

Related

Creating CUDA C library using CMake

I've the following code structure for my library
|-build
|-example
|-CMakeLists.txt
|-main_VecAdd.cu
|-include
|-VonNeumann
|-utils.h
|-VecAdd.h
|-CMakeLists.txt
|-src
|-CMakeLists.txt
|-utils.c
|-VecAdd.c
|-CMakeLists.txt
CMakeLists.txt for folders example, include, src and main_folder are as follows (in order respectively):
project(VonNeumann LANGUAGES CUDA C)
add_executable(main_VecAdd main_VecAdd.cu)
set_target_properties(VonNeumann PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(main_VecAdd
PRIVATE
VonNeumann)
project(VonNeumann LANGUAGES CUDA C)
project(VonNeumann LANGUAGES CUDA C)
add_library(VonNeumann utils.c VecAdd.c)
target_include_directories(VonNeumann
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../include)
cmake_minimum_required(VERSION 3.16.3)
project(VonNeumann LANGUAGES CUDA C)
# Adding subdirectories
add_subdirectory(include)
add_subdirectory(src)
# Giving an option to include code in examples or not
option(BUILD_EXAMPLES "Whether or not to build examples" ON)
if (BUILD_EXAMPLES)
message(STATUS "Building examples...")
add_subdirectory(example)
endif()
When I run cmake .. from build directory, everything works well however I get the following error when I run make command:
[ 16%] Linking C static library libVonNeumann.a
[ 50%] Built target VonNeumann
[ 66%] Linking CUDA device code CMakeFiles/main_VecAdd.dir/cmake_device_link.o
[ 83%] Linking CUDA executable main_VecAdd
/usr/bin/ld: CMakeFiles/main_VecAdd.dir/main_VecAdd.cu.o: in function `main':
tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x111): undefined reference to `RandVecFP32(float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x122): undefined reference to `RandVecFP32(float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x133): undefined reference to `ZeroVecFP32(float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x144): undefined reference to `PrintVec(float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x155): undefined reference to `PrintVec(float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x166): undefined reference to `PrintVec(float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x17d): undefined reference to `VecAddFP32(float*, float*, float*, int)'
/usr/bin/ld: tmpxft_000058c9_00000000-6_main_VecAdd.cudafe1.cpp:(.text+0x19a): undefined reference to `PrintVec(float*, int)'
collect2: error: ld returned 1 exit status
make[2]: *** [example/CMakeFiles/main_VecAdd.dir/build.make:105: example/main_VecAdd] Error 1
make[1]: *** [CMakeFiles/Makefile2:163: example/CMakeFiles/main_VecAdd.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
I know that the error is because of failed linking but I can't figure out how to resolve this.
P.S. I've tested this same code without CUDA part and it works just fine.
As #talonmies suggests, the problem is likely you trying to use functions implemented in your .cu file, in your .c file: CUDA uses "C++ linkage", that the function symbols appear in a certain way in the compiled object file, which differs from how function symbols appear when compiled using C.
To allow your C code to be used by C++ code, you must adapt the declarations to be read differently in C++ (or CUDA), in utils.h and VecAdd.h like so:
#ifdef __cplusplus
extern "C"
{
#endif
void PrintVec(float*, int);
// ... or whatever you're defining
#ifdef __cplusplus
}
#endif
See also:
https://isocpp.org/wiki/faq/mixing-c-and-cpp
How to use C code in C++
By the way - you're using too many CMakeLists.txt files. You don't need one of these for every folder. In fact, for a project as small as yours, a top-level CMakeLists.txt and perhaps another one for the examples would have sufficed. Subdirectory-specific CMakeLists.txt files are appropriate where the contents of the subdirectory is worked on relatively independently, and the top-level CMakeLists.txt does not need to be aware of the dependencies and other configuration work towards producing the targets that do get used outside.

How do i resolve this error I am trying to compile some functions and create a static library but I am getting this error

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.0: in function '_start' :
(.text+0x24): undefined reference to 'main'
Collect2: error: ld returned to 1 exit status
If you're using CMake check if you're really compiling a library not an executable. This error can occur if you have
add_executable(${PROJECT_NAME} ${SOURCES})
instead of
add_library(${PROJECT_NAME} ${SOURCES})
The latter should compile a library; a library doesn't have the main().

Is there an easier way to compile this project

Under Linux(Ubuntu) I'm writing a CMakeLists.txt with CLion to compile my project which is a little game written in C. How do I fix these errors?
Here's a link to the entire source code.
Any help will be greatly appreciated
I have tried to rewrite my .h files. It was primarily an issue about linking SDL and SDL_images.
I have tried to compile the main with gcc main.c -o main -lSDL -lSDL_image.
Here's the CMakeLists.txt
cmake_minimum_required(VERSION 3.7)
project(SOKOBAN)
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lmingw32")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
include_directories(${PROJECT_SOURCE_DIR}/include)
link_directories(${PROJECT_SOURCE_DIR}/lib)
find_package(SDL REQUIRED)
find_package(SDL)
find_package(SDL_image)
set(SOURCE_FILES main.c jeu.c jeu.h editeur.c editeur.h
fichiers.c fichiers.h Constantes.h hsokoban.h)
add_executable(SOKOBANR ${SOURCE_FILES})
target_link_libraries(SOKOBANR SDL_image SDL)
The error is:
[ 20%] Linking C executable SOKOBANR
CMakeFiles/SOKOBANR.dir/jeu.c.o: In function `jouer':
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:12: multiple definition of `jouer'
CMakeFiles/SOKOBANR.dir/main.c.o:/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:12: first defined here
/usr/bin/ld: skipping incompatible /home/mahamad/github/SOKOBAN/SOKOBAN/lib/libSDL.a when searching for -lSDL
CMakeFiles/SOKOBANR.dir/main.c.o: In function `jouer':
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:72: undefined reference to `deplacerJoueur'
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:76: undefined reference to `deplacerJoueur'
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:80: undefined reference to `deplacerJoueur'
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:84: undefined reference to `deplacerJoueur'
CMakeFiles/SOKOBANR.dir/jeu.c.o: In function `jouer':
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:72: undefined reference to `deplacerJoueur'
CMakeFiles/SOKOBANR.dir/jeu.c.o:/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:76: more undefined references to `deplacerJoueur' follow
CMakeFiles/SOKOBANR.dir/fichiers.c.o: In function `sauvegarderNiveau':
/home/mahamad/github/SOKOBAN/SOKOBAN/fichiers.c:67: undefined reference to `fprint'
collect2: error: ld returned 1 exit status
CMakeFiles/SOKOBANR.dir/build.make:128: recipe for target 'SOKOBANR' failed
make[3]: *** [SOKOBANR] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/SOKOBANR.dir/all' failed
make[2]: *** [CMakeFiles/SOKOBANR.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/SOKOBANR.dir/rule' failed
make[1]: *** [CMakeFiles/SOKOBANR.dir/rule] Error 2
Makefile:118: recipe for target 'SOKOBANR' failed
make: *** [SOKOBANR] Error 2```
If you get such errors you need to look into each of them:
CMakeFiles/SOKOBANR.dir/jeu.c.o: In function `jouer':
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:12: multiple definition of `jouer'
CMakeFiles/SOKOBANR.dir/main.c.o:/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:12: first defined here
The linker thinks that you have (at least) two definitions of jouer. Since both referenced locations are the same I assume that you 1. include "jeu.c" instead of "jeu.h" in your "main.c", and 2. link both "main.o" and "jeu.o".
/usr/bin/ld: skipping incompatible /home/mahamad/github/SOKOBAN/SOKOBAN/lib/libSDL.a when searching for -lSDL
The library "libSDL.a" you provide is not compatible to the target system. Your target system seems to be Linux.
For which system is the library?
Did you compile it yourself or did you download it?
CMakeFiles/SOKOBANR.dir/main.c.o: In function `jouer':
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:72: undefined reference to `deplacerJoueur'
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:76: undefined reference to `deplacerJoueur'
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:80: undefined reference to `deplacerJoueur'
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:84: undefined reference to `deplacerJoueur'
CMakeFiles/SOKOBANR.dir/jeu.c.o: In function `jouer':
/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:72: undefined reference to `deplacerJoueur'
CMakeFiles/SOKOBANR.dir/jeu.c.o:/home/mahamad/github/SOKOBAN/SOKOBAN/jeu.c:76: more undefined references to `deplacerJoueur' follow
There are references (calls) of deplacerJoueur but you don't define it. Or the source file with the definition (implementation) is not added to the list of modules.
CMakeFiles/SOKOBANR.dir/fichiers.c.o: In function `sauvegarderNiveau':
/home/mahamad/github/SOKOBAN/SOKOBAN/fichiers.c:67: undefined reference to `fprint'
This is clearly a typo. You mean fprintf() with a trailing 'f' for sure.
collect2: error: ld returned 1 exit status
Because of all the errors the linker is not successful, and it tells you.
CMakeFiles/SOKOBANR.dir/build.make:128: recipe for target 'SOKOBANR' failed
Because of all the errors the build is not successful, and it tells you.

building project with libcurl doesn't work under linux

i am attempting to build a little project in C under Linux in Eclipse Juno. As I include the libcurl library, I think the linker throw always the error cannot find -lcurl. I know there are several posts on the internet, but nothing really helps. The whole looks like this:
Building target: c_template
Invoking: GCC C Linker
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/bin/armv7a-vfp-neon-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc -L/usr/lib --sysroot=/usr/local/oecore-i686-arm/sysroots/armv7a-vfp-neon-oe-linux-gnueabi -o "c_template" ./src/atCommand.o ./src/charDevice.o ./src/curl.o ./src/debug.o ./src/linux_prototype.o ./src/output.o ./src/simStatus.o ./src/urc.o ./src/wwan.o -lpthread -lcurl
from <command-line>:0:
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/defs.h:87:10: warning: type defaults to 'int' in declaration of 'BOOL' [-Wimplicit-int]
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/atCommand.h:56:12: warning: 'atCommandsHandler' defined but not used [-Wunused-variable]
/home/ubuntu/Documents/eCall/hwell_06/workspace_hwell_06/c_template/inc/debug.h:60:12: warning: 'deviceHandler' defined but not used [-Wunused-variable]
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libpthread.so while searching for pthread
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libcurl.so while searching for curl
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: error: cannot find -lcurl
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libc.so while searching for c
../src/curl.c:66: error: undefined reference to 'curl_global_init'
../src/curl.c:69: error: undefined reference to 'curl_easy_init'
../src/curl.c:72: error: undefined reference to 'curl_slist_append'
../src/curl.c:73: error: undefined reference to 'curl_slist_append'
../src/curl.c:76: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:79: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:82: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:85: error: undefined reference to 'curl_easy_setopt'
../src/curl.c:98: error: undefined reference to 'curl_easy_perform'
../src/curl.c:101: error: undefined reference to 'curl_easy_strerror'
../src/curl.c:105: error: undefined reference to 'curl_slist_free_all'
../src/curl.c:108: error: undefined reference to 'curl_easy_cleanup'
../src/curl.c:112: error: undefined reference to 'curl_global_cleanup'
collect2: ld returned 1 exit status
make: *** [c_template] Error 1
I already set up the paths for the library for the linker:
For the library search path (-L) : /usr/lib
and for libraries (-l): curl
My command line pattern looks like this:
${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX} ${OUTPUT} ${INPUTS}
Can anyone helps me. Would be great.
Thanks a lot
You're crosscompiling c_template for ARM so you'll need to install the libcurl for ARM in your cross-compile environment. Right now it finds the libcurl for your i686 host and it cannot use that as shown in:
/usr/local/oecore-i686-arm/sysroots/i686-oesdk-linux/usr/libexec/armv7a-vfp-neon-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/4.6.3/ld: warning: skipping incompatible /usr/lib/libcurl.so while searching for curl
So first compile/install libcurl for your target platform in your compile environment and make sure your compiler can find that.

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).

Resources