getting error when i compile c program through putty - c

/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)]

Related

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

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

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

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.

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

Getting undefined reference to 'clock_gettime' error, for curl program

Gretings,
I have cross compile, OpenSSl , libssh2 and finally cURL, Don't know why it has generated only static library. Anyway I tried to run sample ftpget.c program by linking all the three libraries but I am getting the following error :
.../libcurl.a(timeval.o): In function 'curlx_tvnow':
timeval.c:(.text+0xfc): undefined reference to 'clock_gettime'
collect2: ld return 1 exit status
make: *** [all] Error 1
Please help me resolve this error, Is there need to cross-compile any other library also ?
Thanks,
Yuvi
Try linking with librt (-lrt).
You need to link with the real-time library.
Use -lrt
gcc ... -lrt ...

Resources