Unable to compile of C++ in JGrasp - c++

I am trying to compile a simple Hello World program in C++ on jGrasp but I am getting the following error
----jGRASP exec: g++ -g -o jGHello.exe jGHello.cpp -lglu32 -lfreeglut -lopengl32
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lfreeglut
collect2.exe: error: ld returned 1 exit status
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
I suppose that jGrasp is unable to compile the program due to -lfreeglut being missing. But I am unable to find any mention of it on the internet.

Compiler cant find -lfreeglut, its could be cause two reasons:
It doesnt exits (look if its already install)
Its not on libs path, then u ve to install it on libs path, or tell C++ compiler where is this lib, u can do it like -L /pathToLib
Ej: g++ -g -o jGHello.exe jGHello.cpp -lglu32 -lfreeglut -lopengl32 -L /pathToLib

Related

How to link a project with multiple files using MinGW?

I've been learning to use visual studio code recently to code in C++ since Visual Studio 2019 were having alot of problems with the Windows SDK.Recently i've succefully link and run an SFML/C++ file on VS Code using MinGw and CMake Gui.Here's the 'Makefile' file that i used to link:
Makefile(no extension):
all:
g++ main.cpp -o main.exe -DSFML_STATIC -I F:\SFMLPrj\StarFirestc\Prefixes\include -L F:\SFMLPrj\StarFirestc\Prefixes\lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype
for the .cpp file(main.cpp) i've tried copy the sample code on https://www.sfml-dev.org/ to test the linking process and everything works fine.
But then when i try to include another header(of a class called 'Game')into to main.cpp and link the following errors occurs in MinGW:
F:\SFMLPrj\StarFirestc>mingw32-make all
g++ main.cpp -o main.exe -DSFML_STATIC -I F:\SFMLPrj\StarFirestc\Prefixes\include -L F:\SFMLPrj\StarFirestc\Prefixes\lib -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x16): undefined reference to `Game::Game()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x21): undefined reference to `Game::Run()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x31): undefined reference to `Game::~Game()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\duch6\AppData\Local\Temp\cc2mmCAA.o:main.cpp:(.text+0x42): undefined reference to `Game::~Game()'
collect2.exe: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
I have searched for 4 hour and still have no idea how to link 2 or more file using MinGW.Can anyone help me ?

Why do I get this error when I compile a C++ program in jgrasp?

----jGRASP exec: gcc -g -o C1.exe C1.c -lglu32 -lfreeglut -lopengl32`
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot find -lfreeglut
collect2.exe: error: ld returned 1 exit status
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
I am using mingw32 compiler and I followed the instructions from the link below:
http://users.csc.calpoly.edu/~akeen/courses/csc101/references/gcc.html
Hope that someone knows what to do
thank you
You probably need to specify the location of the freeglut library with the flag -L /path/to/freeglut, so compile as
gcc -g -o C1.exe C1.c -L/path/to/freeglut -lglu32 -lfreeglut -lopengl32
or, if you use an IDE, there should be an option to specify the location of the libraries used by the linker.
See http://users.csc.calpoly.edu/~phatalsk/references/jGrasp_gcc_Setup/GCC_JGrasp_Install.html
Settings/Compiler Settings/Workspace, add the flag to C/L field.

Compiling Dynamically Linked Library in C++ with Run Path Issue

I'm busy trying to compile and link a c++ program using the following make file
driver.so:driver.cpp
g++ -c driver.cpp -o driver.so
g++ -L/tokenlib/libtokenlib.so driver.so -o linked
but I'm getting the error
g++ -c driver.cpp -o driver.so
g++ -L/tokenlib/libtokenlib.so driver.so -o linked
driver.so: In function `main':
driver.cpp:(.text+0x9): undefined reference to `tokenlib::acquire_token()'
collect2: error: ld returned 1 exit status
make: *** [driver.so] Error 1
and my file hierarchy is
/root
makefile
driver.cpp
/tokenlib
libtokenlib.so
I've been told that adding -Wl,-rpath=./tokenlib to my g++ arguements would solve the problem so I tried like this
driver.so:driver.cpp
g++ -c driver.cpp -o driver.so -Wl,-rpath=./tokenlib
g++ -L/tokenlib/libtokenlib.so driver.so -o linked -Wl,-rpath=./tokenlib
but it still isn't working.
I'm a complete novice and any help would be appreciated.
The linker usually refers to .a (stub) libraries, not to .so files!
-L options specify the paths, the lnker should take in account.
The -l<mystuff> option tries to resolve a library named libmystuff.a from any of the given path's of the -L options, or compiler intrinsic library search paths.

C++: linker cannot find -lcrypto, but the library is in the path

I am compiling a C++ application using GNU g++. The project takes advantage of OpenSSL libraries.
Background
On my machine (a 64 bit CentOS quad core) I compile and link my files.
g++ -g -c -L/usr/local/lib/ -L/usr/lib64/
-I/usr/local/include/ -I/usr/local/ssl/include/
-lcrypto mysrc1.cpp mysrc2.cpp mysrc3.cpp
g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto
*.o -o ./myapp.out
My application uses function MD5 which is contained in libcrypto.so. As you can see I specify to g++ the dirs where to search using the -L, -I options and which libraries to look for with the -l<lib-name> option. There are some trivial paths like /usr/local/lib which can be omitted of course, but I specified them because the makefile is parametric.
The problem
My problem is that I can successfully compile my stuff (first command), but linking fails (second command):
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
make: * [cppsims_par] Error 1
But I did check folders and everything... libcrypto.so is inside /usr/lib64/. What is going on?
It may help if you try strace to find why it failed the file lookup
strace -f -e trace=file g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto
*.o -o ./myapp.out
I did find the problem and it is related to this question: ld cannot find an existing library
Actually I had no symlink libcrypto.so and the compiler was not able to find the library...
I had related issue, and resolved it after inspecting the trace.
I had
-L<my/path/to/lib> -llib_some_library
when it should have been
-L<my/path/to/lib> -lsome_library

link to boost library

I am trying to build a project using Boost's Asio , but I am getting linking error:
g++ -o homework main.o -L/usr/lib64/qt-3.3/lib -L/usr/X11R6/lib64 -L/home/student/boost_1_46_1/libs -lboost_system -lqt-mt -lXext -lX11 -lm
/usr/bin/ld: cannot find -lboost_system
collect2: ld returned 1 exit status
make: *** [homework] Error 1
How can I resolve the problem?
I think it's a typo. You said -l boost_system in command line, while it should be -lboost_system.
Update:
Nope! I get my answer back. Just found that it's OK to pass -l <libname>. In fact it's equal to -l<libname>. As others said, double-check paths.