GLFW header is recognized, but the methods included in it aren't - c

Ok so I have a bit of a weird issue. I downloaded GLFW through the terminal on my Debian WSL. VSCode (and the autocomplete) acknowledged the header files AND the methods exist, even giving the method information on hover. However, GCC does know the header file exists (and does not throw an error when referenced), yet throws errors when I reference the methods included in the header.
Screenshot
Errors thrown:
gcc -o ge all-src/new-src/GameObject.o all-src/new-src/main.o all-src/new-src/V2.o all-
src/new-src/V3.o -Wall
all-src/new-src/main.o: In function `main':
main.c:(.text+0x9): undefined reference to `glfwInit'
main.c:(.text+0x18): undefined reference to `glfwWindowHint'
main.c:(.text+0x27): undefined reference to `glfwWindowHint'
main.c:(.text+0x36): undefined reference to `glfwWindowHint'
main.c:(.text+0x57): undefined reference to `glfwCreateWindow'
main.c:(.text+0x78): undefined reference to `glfwTerminate'
main.c:(.text+0x8b): undefined reference to `glfwMakeContextCurrent'
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'all' failed
make: *** [all] Error 1

Related

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.

ALSA Lib 1.1.2 Compilation error

I am trying to cross compile ALSA Lib application for linux-arm based processor. I am using eclipse to do the build for me. The build phase of the application is successful but I get errrors when the gcc linker tries to complete.
I get the following errors
Building target: sound
Invoking: Cross GCC Linker
arm-linux-gnueabihf-gcc -L/proc/asound -L/srv/nfs/rootfs/usr/lib -Wl,-rpath-link,/srv/nfs/rootfs/usr/lib -L/srv/nfs/rootfs/lib -Wl,-rpath-link,/srv/nfs/rootfs/lib -o "sound" ./play.o
./play.o: In function main':
/home/neonws/sound/Debug/../play.c:13: undefined reference tosnd_pcm_open'
makefile:29: recipe for target 'sound' failed
/home/neonws/sound/Debug/../play.c:14: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:20: undefined reference tosnd_pcm_hw_params_malloc'
/home/neonws/sound/Debug/../play.c:21: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:26: undefined reference tosnd_pcm_hw_params_any'
/home/neonws/sound/Debug/../play.c:27: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:32: undefined reference tosnd_pcm_hw_params_set_access'
/home/neonws/sound/Debug/../play.c:33: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:38: undefined reference tosnd_pcm_hw_params_set_format'
/home/neonws/sound/Debug/../play.c:39: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:44: undefined reference tosnd_pcm_hw_params_set_rate_near'
/home/neonws/sound/Debug/../play.c:45: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:50: undefined reference tosnd_pcm_hw_params_set_channels'
/home/neonws/sound/Debug/../play.c:51: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:56: undefined reference tosnd_pcm_hw_params'
/home/neonws/sound/Debug/../play.c:57: undefined reference to snd_strerror'
/home/neonws/sound/Debug/../play.c:62: undefined reference tosnd_pcm_hw_params_free'
/home/neonws/sound/Debug/../play.c:64: undefined reference to snd_pcm_prepare'
/home/neonws/sound/Debug/../play.c:65: undefined reference tosnd_strerror'
/home/neonws/sound/Debug/../play.c:71: undefined reference to snd_pcm_writei'
/home/neonws/sound/Debug/../play.c:72: undefined reference tosnd_strerror'
/home/neonws/sound/Debug/../play.c:78: undefined reference to `snd_pcm_close'
collect2: error: ld returned 1 exit status
make: *** [sound] Error 1
11:15:58 Build Finished (took 75ms)
I am using the Sample Playback Program from ASLA-LIB api.
I am wondering what is causing the linker to fail?
You're missing an asound library linkage, add -lasound to your linking flags (see this question which tells where to do that properly in Eclipse). And probably remove -L/proc/asound, I don't think you have your libraries there.

Trying to use libcurl in my program and getting "undefined reference" errors

I am getting the following errors:
/tmp/ccno287V.o: In function `download_feed':
feedObtain.c:(.text+0xb9): undefined reference to `curl_easy_init'
feedObtain.c:(.text+0xde): undefined reference to `curl_easy_setopt'
feedObtain.c:(.text+0xff): undefined reference to `curl_easy_setopt'
feedObtain.c:(.text+0x10b): undefined reference to `curl_easy_perform'
collect2: error: ld returned 1 exit status
Command used to get libcurl:
apt-get install libcurl4-gnut
Your program is not linked with the libcurl library and hence the linker complains that it could resolve symbols. Link the library with:
cc feedObtain.c -lcurl
Note that the library must be specified at the end of the commandline options.

getting error when i compile c program through putty

/tmp/ccfg3L9u.o: In function `main':
Allgo-API-Test.c:(.text+0x968): undefined reference to `mport_get_sub_metadata_entries'
Allgo-API-Test.c:(.text+0xb24): undefined reference to `mport_set_play_scope'
collect2: error: ld returned 1 exit status
Makefile:86: recipe for target 'bin/MediaPort.elf' failed
make: *** [bin/MediaPort.elf] Error 1
I think you miss to link additional library while compiling file Allgo-API-Test.c
Before compiling this file you should have library which contain definition of mport_get_sub_metadata_entries and mport_set_play_scope. Once you get that library you can use below command to compile.
g++ Allgo-API-Test.c -l(your library) [-L(path to your library)]

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

Resources