graphics.h install issues manjaro - c

I'm currently attempting to install graphics.h on manjaro, but the library doesn't seem to work. Currently I am getting the following errors when I try running the following code:
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
int main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
circle(50, 50, 30);
delay(500000);
closegraph();
return 0;
}
/usr/bin/ld: /tmp/ccm2VUMu.o: in function `main':
circle.c:(.text+0x32): undefined reference to `initgraph'
/usr/bin/ld: circle.c:(.text+0x46): undefined reference to `circle'
/usr/bin/ld: circle.c:(.text+0x55): undefined reference to `delay'
/usr/bin/ld: circle.c:(.text+0x5a): undefined reference to `closegraph'
collect2: error: ld returned 1 exit status
I installed graphics.h from the arch user repository using yay, and have made sure to install it's dependencies (guile, sdl, sdl_image), so I'm not sure where to go next.

Related

gcc undefined reference to header of multiple files

I have a sample code temp.c:
#include "win.h"
win.h is in /home/me/Documents/Code/libs/TUI/win.h and has all the declared functions
which functions are defined in some files in /home/me/Documents/Code/libs/TUI/win/[lots of files].c which every file starts with
#include "../win.h"
//functions
So while using gcc -I /home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/me/Documents/Code/temp, gcc returns every function used in temp.c declared in win.h as undefined
Exact output:
gcc -g -I/home/me/Documents/Code/libs/TUI /home/me/Documents/Code/temp.c -o /home/pk/Documents/Code/temp
/usr/bin/ld: /tmp/cc4berEn.o: in function `main':
/home/me/Documents/Code/temp.c:8: undefined reference to `innit'
/usr/bin/ld: /home/me/Documents/Code/temp.c:11: undefined reference to `newTable'
/usr/bin/ld: /home/me/Documents/Code/temp.c:13: undefined reference to `tableSetHeaders'
/usr/bin/ld: /home/me/Documents/Code/temp.c:35: undefined reference to `tableAppendRow'
/usr/bin/ld: /home/me/Documents/Code/temp.c:45: undefined reference to `printTable'
collect2: error: ld returned 1 exit status
notes
Using -I /home/me/Documents/Code/libs/TUI/win.h returns fatal error: win.h: No such file or directory 3 | #include "win.h"
/home/me/Documents/Code/libs/TUI is a folder
Writing every source file's name is not an option
Already tried this
-g for debug

How do I link and compile Raylib on windows?

I have installed the raylib migw from the official source. The installation directory is C:\raylib\raylib. I have written the sample program from the website as follows.
#include "raylib.h"
int main(void){
const int screenWidth = 800;
const int screenHeight = 600;
InitWindow(screenWidth, screenHeight, "raylib basic window test");
SetTargetFPS(60);
while(!WindowShouldClose()){
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
CloseWindow();
return 0;
}
I have compiled it using gcc main.c -I C:\raylib\raylib\src and when I do this, I'm getting the following error
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x37): undefined reference to `InitWindow'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x43): undefined reference to `SetTargetFPS'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x48): undefined reference to `WindowShouldClose'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x58): undefined reference to `BeginDrawing'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0x86): undefined reference to `ClearBackground'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0xce): undefined reference to `DrawText'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0xd3): undefined reference to `EndDrawing'
C:\Users\jaych\AppData\Local\Temp\ccOHQPti.o:main.c:(.text+0xdd): undefined reference to `CloseWindow'
collect2.exe: error: ld returned 1 exit status
How do I fix this?
Add libraylib.a file into lib folder, then run the following command
gcc main.c -o main -O1 -Wall -std=c99 -Wno-missing-braces -L ./lib/ -lraylib -lopengl32 -lgdi32 -lwinmm

Math library linking error in CLion on Linux [duplicate]

This question already has answers here:
How to link to the C math library with CMake?
(3 answers)
Closed 3 years ago.
To do my homework I need #include "math.h", but after updating GCC and CMake, CLion can't link my project files. What should I do to fix this problem?
In Settings -> Build, Execution and Deployment -> Toolchains CLion says that CMake version is 3.15.3 and GDB version is 8.3 and it's OK.
I already tired to reinstall GCC, CMake and CLion, but it didn't work. Also I tired to search some info on StackOverflow, but still nothing works.
Main.c:
#include <stdio.h>
#include <math.h>
int main() {
FILE *output;
output = fopen("/home/vadimsam/CLionProjects/untitled/data.txt", "w");
double x=0.,v=0.,t=0.,m=0.,k=0.,dt = 1e-5,xn,vn;
while (t < 1e1) {
vn = -x*sqrt((k/m))*cos(sqrt((k/m))*t)+v*cos(sqrt((k/m))*t);
xn = -x*cos(sqrt((k/m))*t)+(v/sqrt((k/m)))*sin(sqrt((k/m))*t);
t += dt; x = xn; v = vn;
fprintf(output, "%lf %lf %lf\n", t, x, v);
}
fclose(output);
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.15)
project(untitled2 C)
set(CMAKE_C_STANDARD 11)
add_executable(untitled2 main.c)
Compiler output:
====================[ Build | untitled2 | Debug ]===============================
/home/vadimsam/.local/share/JetBrains/Toolbox/apps/CLion/ch-0/193.5096.27/bin/cmake/linux/bin/cmake --build /home/vadimsam/CLionProjects/untitled2/cmake-build-debug --target untitled2 -- -j 8
Scanning dependencies of target untitled2
[ 50%] Building C object CMakeFiles/untitled2.dir/main.c.o
[100%] Linking C executable untitled2
CMakeFiles/untitled2.dir/main.c.o: In function `main':
/home/vadimsam/CLionProjects/untitled2/main.c:10: undefined reference to `sqrt'
/home/vadimsam/CLionProjects/untitled2/main.c:10: undefined reference to `sqrt'
/home/vadimsam/CLionProjects/untitled2/main.c:10: undefined reference to `cos'
/home/vadimsam/CLionProjects/untitled2/main.c:10: undefined reference to `sqrt'
/home/vadimsam/CLionProjects/untitled2/main.c:10: undefined reference to `cos'
/home/vadimsam/CLionProjects/untitled2/main.c:11: undefined reference to `sqrt'
/home/vadimsam/CLionProjects/untitled2/main.c:11: undefined reference to `cos'
/home/vadimsam/CLionProjects/untitled2/main.c:11: undefined reference to `sqrt'
/home/vadimsam/CLionProjects/untitled2/main.c:11: undefined reference to `sqrt'
/home/vadimsam/CLionProjects/untitled2/main.c:11: undefined reference to `sin'
collect2: error: ld returned 1 exit status
CMakeFiles/untitled2.dir/build.make:83: recipe for target 'untitled2' failed
make[3]: *** [untitled2] Error 1
CMakeFiles/Makefile2:75: recipe for target 'CMakeFiles/untitled2.dir/all' failed
make[2]: *** [CMakeFiles/untitled2.dir/all] Error 2
CMakeFiles/Makefile2:82: recipe for target 'CMakeFiles/untitled2.dir/rule' failed
make[1]: *** [CMakeFiles/untitled2.dir/rule] Error 2
Makefile:118: recipe for target 'untitled2' failed
make: *** [untitled2] Error 2
I need to compile my project.
The math library is usually linked as a separate library (conveniently named m) that you explicitly need to link with.
You tell CLion (through its CMakeLists.txt file) to link with libraries with the target_link_libraries command:
target_link_libraries(untitled2 m)

Undefined reference to "graphics.h" functions in Ubuntu 19.04 in CLion IDE

I installed graphics.h library on my Ubuntu 19.04, and when I write some code in my CLion IDE, it successfully includes the graphics.h Header file, and also after writing some basic functions, the IDE doesn't show any errors, but when I compile the Code it gives Errors.
My Code:
#include <stdio.h>
#include <graphics.h>
int main() {
int gd = DETECT, gm;
detectgraph(&gd, &gm);
initgraph(&gd, &gm, NULL);
line(10, 10, 50, 50);
closegraph();
}
My CMakeList.txt File:
cmake_minimum_required(VERSION 3.14)
project(CGR_MP C)
set(CMAKE_C_STANDARD 11)
include_directories("//usr//local//lib//libgraph-1.0.2//")
build_command("lgraph")
add_executable(CGR_MP main.c)
Errors:
====================[ Build | CGR_MP | Debug ]==================================
/snap/clion/73/bin/cmake/linux/bin/cmake --build /home/prathamesh/Desktop/College/Sem-2/CGR-MP/cmake-build-debug --target CGR_MP -- -j 2
Scanning dependencies of target CGR_MP
[ 50%] Building C object CMakeFiles/CGR_MP.dir/main.c.o
[100%] Linking C executable CGR_MP
/usr/bin/ld: CMakeFiles/CGR_MP.dir/main.c.o: in function `main':
/home/prathamesh/Desktop/College/Sem-2/CGR-MP/main.c:7: undefined reference to `detectgraph'
/usr/bin/ld: /home/prathamesh/Desktop/College/Sem-2/CGR-MP/main.c:8: undefined reference to `initgraph'
/usr/bin/ld: /home/prathamesh/Desktop/College/Sem-2/CGR-MP/main.c:10: undefined reference to `line'
/usr/bin/ld: /home/prathamesh/Desktop/College/Sem-2/CGR-MP/main.c:12: undefined reference to `closegraph'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/CGR_MP.dir/build.make:84: CGR_MP] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/CGR_MP.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/CGR_MP.dir/rule] Error 2
make: *** [Makefile:118: CGR_MP] Error 2
Despite everything being successfully installed, it shows all Graphics functions as undefined reference

Using nan() on solaris-sparc

#include <math.h>
int main() {
nan("");
}
The above code works on Linux with gcc fn.c -lm. It doesn't on solaris-sparc. How do I fix this?
The error message is:
Undefined symbol nan, first referenced in file /var/tmp//ccsdneUZ.o ld: fatal: Symbol referencing errors. No output written to test collect2: ld returned 1 exit status.

Resources