mingw cannot find my dependencies folder for GLFW - c++

I'm trying to compile the code found in https://www.glfw.org/documentation. This code is in "main.cpp" and I have a folder in the same directory called "dependencies" containing: "glfw3.h", "glfw3.lib" and "libglfw3.a".
project directory
dependencies
I go to the directory in powershell and run:
g++ main.cpp -ldependencies .\dependencies\libglfw3.a -lopengl32 -lgdi32
and it returns:
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldependencies: No such file or directory
collect2.exe: error: ld returned 1 exit status
What have I done wrong?
I've looked all the internet for solutions but none have worked even when I exactly do what is shown on the tutorial or solution, im quite stuck. I think its because im attempting to do this without an IDE (I used visual studio) and until recently i've only did C++ development with an IDE and i'm inexperienced with compiling and linking outside of IDE's.

g++ main.cpp -ldependencies .\dependencies\libglfw3.a -lopengl32 -lgdi32
should be
g++ main.cpp -Ldependencies -lglfw3 -lopengl32 -lgdi32
-L for a directory to search, -l for the name of the library to link with.

Related

Cygwin: Error while linking .lib files

I'm new with Cygwin and currently I'm trying to build a little project which would encrypt some files.
The problem I'm having is that when I try to build the .cpp with the command:
gcc test.cpp -I /cygdrive/c/OpenSSL-Win32/include/ -L/cygdrive/c/OpenSSL-Win32/lib/MinGW -lcrypto -lssl
(OpenSSL is installed at cygdrive/c/OpenSSL-Win32) I get the error:
/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld: cannot find -lcrypto
/usr/lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld: cannot find -lssl
collect2: error: ld returned 1 exit status
I can't understand why It can't to find the libraries, because I clearly have libssl.lib and libcrypto.lib there. Sorry if my question sounds silly I'm with all this. Thanks.

Compile OpenGL application from Windows on Linux

My friend made OpenGL graphic engine, but he is working on Windows. I want to compile project with it.
I installed all required libs with headers, but now problem is with linking (project in Code::Blocks). I found paths for /usr/lib/libSOIL.a and /usr/local/lib/libglfw3.a, but what about:
C:\Program Files (x86)\CodeBlocks\MinGW\lib\libopengl32.a
C:\Program Files (x86)\CodeBlocks\MinGW\lib\assimp_debug-dll_win32\assimp.lib
Also, what I must modify in project file to compile it? It requires: glfw3, glm, gl3w.h, assimp, SOIL (this is what I get from .hpp files). I installed all headers (downloaded sources and make && make install)...
I tried to compile it from terminal with g++, but I don't know switches for libraries.
Current situation:
$ g++ Camera.o Entity.o Frustum.o gl3w.o Light.o Material.o Mesh.o Model.o ModelPart.o Shader.o Texture.o Utilities.o ../main.o -o main -L/usr/local/lib/libglfw3.a -lX11 -lXext -lXt -lSM -lGLU -lglut -lSOIL
/usr/bin/ld: gl3w.o: undefined reference to symbol 'glXGetProcAddress'
/usr/bin/ld: note: 'glXGetProcAddress' is defined in DSO /usr/lib/nvidia-313-updates/libGL.so.1 so try adding it to the linker command line
/usr/lib/nvidia-313-updates/libGL.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
(i added too much libraries to command line, I know)
EDIT
Added -lGL and -ldl and some problems comes out. Now, I'll trying compile it with makefile...
libopengl32 -> libGL.a
assimp -> libassimp.a ?
You gotta provide the Makefile you're compiling it with.

Static-linking of SDL2 libraries

I am using Windows 7, Code::Blocks and MinGW. I have little to no experience when it comes to compiling/building anything, especially when Code::Blocks doesn't use makefiles.
I downloaded SDL2-devel-2.0.0-mingw.tar.gz (SDL Development Libraries) from http://www.libsdl.org/tmp/download-2.0.php, and I'd like to create a standalone executable using SDL2 libraries, but so far I've always had to bundle the SDL2.dll file with the executable to make it work.
I've heard that I can not static-link dynamic libraries, so my only option seems to be doing something with the source files using the file SDL2-2.0.0.tar.gz (Source Code) from the link I mentioned above. However, I do not know what I should do with those.
What I managed to try with the source files is importing the Visual Studio project to Code::Blocks and building it, but it tells me "sdl-config No such file or directory" (I do not know what triggered that). I'm also not sure if building merely gives me an executable, with which I do not know what I can do to link it to my own executable.
A fool proof idiot's step by step guide would be the best bet to solve this case.
EDIT:
I managed to compile the SDL libraries with the guide Jonas provided, and got a libSDL2.a file.
At first I only added the path of libSDL2.a to "Link libraries:" -section of Code::Blocks, but I got a bunch of errors such as "SDL_Init() not declared in this scope".
In addition to the libSDL2.a path, I also added the path of SDL2-2.0.0\include to the Compiler's search directory as well as the path of SDL2-2.0.0\build.libs to the Linker's search directory. I also wrote this to my test file: #include "SDL.h". My test file now looks like this:
#include "SDL.h"
int main( int argc, char* args[] ) {
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}
It appears it did fix the declaration problem, but now Code::Blocks opened a SDL_mmjoystick.c file and gave me even more errors: "undefined reference to 'waveInClose#4'", "undefined reference to 'waveOutClose#4'", "undefined reference to 'joyGetNumDevs#0'" and tons of other ones.
Here's a screenshot of what's happening, note the different color of #include texts, I'm not sure why that happens: http://gyazo.com/00656a9c1e57a2bd0db1414fa7d68ced.png
I am not sure how to correctly take this library into use. Any help in this case, or should I make another question for it?
EDIT:
I added -lSDL2 to the linker options and deleted the other parameters. Now it builds fine:
mingw32-g++.exe -Wall -fexceptions -g -IC:\Users\User\Desktop\SDL2-2.0.0\include -c "C:\Users\User\Desktop\CppProjects\SDL project\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -Wall -fexceptions -g -IC:\Users\User\Desktop\SDL2-2.0.0\include -c "C:\Users\User\Desktop\CppProjects\SDL project\thetestfile.cpp" -o obj\Debug\thetestfile.o
mingw32-g++.exe -LC:\Users\User\Desktop\SDL2-2.0.0\build\.libs -o "bin\Debug\SDL project.exe" obj\Debug\main.o obj\Debug\thetestfile.o -lSDL2 ..\..\SDL2-2.0.0\build\.libs\libSDL2.a C:\Users\User\Desktop\SDL2-2.0.0\build\.libs\libSDL2.a -mwindows
Output size is 945.80 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings (0 minutes, 1 seconds)
But when I try to run it, it says my computer lacks SDL2.dll, while the whole point was to static-link.
So currently I have the path to build/.libs in my Link libraries -settings, -lSDL2 in the Other linker options, and for search directories I have the path to SDL2-2.0.0/include for the compiler and SDL2-2.0.0/build/.libs for the linker.
In the build/.libs directory I can also see libSDL2.a, libSDL2.dll.a, libSDL2.la and libSDL2.lai files, which I don't know what they are.
It's not necessary to recompile the library,
SDL2 is given with static-link library named "libSDL2.a"
on the folder "SDL2-2.0.0\i686-w64-mingw32\lib\".
Just be sure to add these options to the linker :
"-lmingw32 -lSDL2main -lSDL2 -mwindows -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc"
on Code:Blocks at "Project / Build Options... / Linket settings / Other linker options"
These options allow you to link with what SDL2.dll was using.
You can retreive them on the file "SDL2-2.0.0\i686-w64-mingw32\bin\sdl2-config"
The magical trick is to delete or rename the file "libSDL2.dll.a"
on the folder "SDL2-2.0.0\i686-w64-mingw32\lib\".
I added a "-" before to keep it in case I need it.
I don't know why this librairy overcomes the other and a clue would be appreciated.
I tried with Code::Blocks 12.11 MinGW32 and it worked.
If you run with some projects that use dynamic-link
and some other which use static-link, you will have to
keep your librairies in two different folders knowing that
"libSDL2main.a" will be in those two.
Sorry for my writing, I'm not used to write in english.
Mike

Linking to ROOT files in xCode

I need to link to the .so files and headers found in /root/lib and /root/include in a project in xcode 3.2.6. ROOT is an analysis framework from CERN.
There is a utility root-config, that will return all the libraries necessary, I can compile on the command line using:
CFLAGS = `root-config --cflags`
GLIBS = `root-config --glibs`
test : main.cpp main.h
g++ $(CFLAGS) $(GLIBS) -g -Wall main.cpp -02 -o test
Program runs fine with no bugs. But, I want to use xcode for the whole project, but can't get it to either
A: use this utility
or
B: search the right paths to the .so files. I have included /root/lib and /root/include in the build variables header_search_paths and library_search_paths under the build settings. I then actually type in the files I need into the other_linker_flags like so:
-llibTree -llibHist -llibRIO -llibCint -llibCore
xcode returns the message:
ld: library not found for -llibTree
collect2: ld returned 1 exit status
Command /Developer/usr/bin/g++-4.2 failed with exit code 1
Does anybody know whats going on? Can xCode compile .so files? Is there some other issue here?
This has nothing to do with ROOT. To link against a library named libSomething.so in your library search path you can use a linker flag -lSomething. You want to link against e.g. libTree.so, so the correct flag to use would be -lTree, not -llibTree which would look for liblibTree.

G++ openGL application under Cygwin

I looked at this post, but it did not help. Builder returns me this:
/cygdrive/c/Users/Itun/workspace/VoxEngine/Debug/../src/main.cpp:30: undefined reference to _glEnable
/cygdrive/c/Users/Itun/workspace/VoxEngine/Debug/../src/main.cpp:31: undefined reference to _glClearColor'`.
What do -lglut32 -lglu32 -lopengl32 flags mean? Where are the libs?
How to create OpenGL project under Cygwin with Eclipse?
UPDATE:
I add -I/usr/include/opengl to g++ and it starts to work. In this folder there is a single file GL.dll. How does this dll influence to the compilation?
The flag -l -lglut32 -lglu32 -lopengl32 tell the linker to link against libraries libglut32, libglu32 and libopengl32
However your error indicated you didn't include any OpenGL header files. (#include <GL/gl.h>, #include <GL/glu.h>)
Cygwin keeps to the Unix way and places libraries in $CYGWINPREFIX/usr/lib and includes in $CYGWINPREFIX/usr/include.