I'm trying to use OneLoneCoder's olcPixelGameEngine, but when I try to compile my file (g++ -o YourProgName YourSource.cpp -lX11 -lGL -lpthread -lpng -lstdc++fs -std=c++17), I get the error:
fatal error: dwmapi.h: No such file or directory
I use g++ 9.2 with MinGW. Where do I find dwmapi.h?
2 problems I'm seeing immediately
First, you're not using the proper build command for MinGW, you're using the Linux GCC build command, which is requiring libraries that don't exist in MinGW.
Instead try something like this:
g++ -o olcExampleProgram.exe olcExampleProgram.cpp -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -ldwmapi -lstdc++fs -static -std=c++17
Second, you're likely using a bad version of MinGW.. Long story short, not all MinGW are created equal and currently, the best version (and the one that has been tested to compile PGE applications) is the version provided by MSYS2.
If you want you can check the PixelGameEngine WIKI page on the subject.
https://github.com/OneLoneCoder/olcPixelGameEngine/wiki/Compiling-on-Windows-with-Other-Compilers
That's the Linux build command, look at this instead:
https://community.onelonecoder.com/2020/05/08/lets-make-an-olcpixelgameengine-application-using-mingw/
Also, next time you probably get quicker help on the discord server
Related
I am trying to use the GSL library with C++ in Xcode and I was having an issue linking to the library.
I am able to link to GSL using the terminal and clang with the following linker flags
clang++ -std=c++17 -Wall -pedantic test.cpp -o test -lgsl -lgslcblas
From the command line I'm able to verify it uses the GSL library for the computation. However in Xcode, I get a "'gsl/gsl_linalg.h' file not found" error when I try to build it. Its called in my header file with
#include <gsl/gsl_linalg.h>
I added -lgsl -lgslcblas into Xcode build settings thru the "Other Linker flags" option.
I also ran
gsl-config --cflags
gsl-config --libs
and got the following output
-I/usr/local/include
-L/usr/local/lib -lgsl -lgslcblas
So it seems like GSL is installed properly and can be used by clang but for some reason when I use clang through Xcode it isn't able to use it. I was also able to manually find that particular header file in /usr/local/include/gsl/gsl_linalg.h
Any ideas on what I'm might be doing wrong?
So I'm trying to run an example SFML program on my Windows laptop. If relevant, the source code is on this page.
So first I make the .o file using this command -
g++ -c a.cpp -ISFML/SFML/include
Where a.cpp is the main file, and my SFML package is located in SFML/SFML.
Then I compile using this command -
g++ a.o -o a -LSFML/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
When I first ran the program I got the errors about not being able to find certain dlls, sfml-graphics-2 etc. So I found them and put them next to the exe. But now when I run, I get this weird error:
The procedure entry point
_ZNSt7__cxx1112basic_stringSt11char_traitsIcESalcEE7reserveEj could not be located in the dynamic link library.
What is going on here?
As the SFML download page states, You could be using the wrong version of the compiler, other library versions of SFML that you have not removed from your working directory that could mismatch between code and linker. Worst case, if your compiler is not listed there, you have to compile SFML yourself:
Get CMake. Get the source code for 2.4.2 by going to the bottom of the SFML download page. Follow this guide on SFML's GitHub repo. Alternatively, you could use the guide on SFML's page but it is for an older version. It might answer some questions that the first guide misses.
Ones CMake have generated the makefiles, you're on your way to build SFML.
Good luck!
I've had this problem for so long so I just wanted to help someone out who had the same problem. I have a windows 10 FYI and MinGW-w64 8.1.0 (if it doesnt work try a 32 bit mingw instead)
for a debug mode (debug is when your still working on the game and would like command prompt to open whenever you run it)
(make sure your in the right directory first by doing "cd")
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -g -m64 -Wall &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics -lsfml-window -lsfml-system
The code above when placed in command will compile everything for you if its all in the same directory so make sure you keep an eye out for that
and now for release mode (if you dont want command prompt to show up)
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -O3 -m64 &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics lsfml-window -lsfml-system -mwindows
Noticed all I added was the -mwindows and the -O3 aswell as removing -g and -Wall which are not necessary since we wont be using command prompt
Make sure to go to SFML/bin and take all the .dlls and put it into the same directory has your .exe sorry xd
Hope this helped.
I'm trying to use X86_64-w64-mingw32-g++ (packaged in Archlinux's MingW package) to cross compile some C++ code into an Windows executable, however I'm having trouble getting past some issues.
I'm calling
x86_64-w64-mingw32-g++ -o build_win/asm build_win/asm.o build_win/asm_lib.o build_win/socket_boost.o -I../extra/etc -fopenmp -lrt -std=c++11 -g -lboost_system -lboost_serialization
from a makefile, but I get thrown the errors:
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lrt
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_system
/usr/lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lboost_serialization
This works fine with native g++, so exactly do I have to change for mingw to compile?
EDIT: I have mingw-w64-boost package installed, which includes boost libraries pre-compiled and ready to be linked. However, it seems the naming convention is a bit different, and -lboost_system for example becomes -llibboost_system-mt (not exactly sure what the -mt suffix entails).
Problem is I can't find the mingw counterpart for -lrt. I've tried with both -lrtm and -lrtutils but in both cases I get:
[...]
undefined reference to `__imp_getsockopt'
Are you sure that -lboost_system and other libraries are present in the same directory as makefile ?
If not then please include -L flag which indicates the location of your library.
For example:
-L /path_openmp -fopenmp -L /path_boost_system/ -lboost_system -L /path_serialization -lboost_serialization
Moreover, you need not include -I and -g flag when creating an executable from .o files. These are needed when you create .o from .cpp files.
There is no rt library on Windows.
You are missing -lws2_32.
$ x86_64-w64-mingw32-nm -A /usr/x86_64-w64-mingw32/lib/*.a 2>/dev/null | grep getsockopt | grep " T "
In the CImg Makefile I notice a flag "-lm" I think this points to the m.lib file. But for some reason it cannot find it during the Linking phase. I am compiling the code using the following command:
nvcc -o FilledTriangles FilledTriangles.cu -I.. -O2 -lm -lgdi32
"nvcc" is just the nvidia CUDA compiler. It should function similar to g++
-lm refers to "libm.so"
In general, -lXYZ is a way of telling the linker that it should resolve the symbols in your compiled code against libXYZ.so (after locating it, usually in /usr/lib).
I'm trying to set up my Netbeans IDE so that it is capable of compiling wxWidgets projects.
There is very similar question:
Setup wxWidget in Netbeans 6.1 C++ On MS Windows?
but the answer is not working for me. And the mentioned versions are a bit outdated.
I use the mingw package for compilation.
There is no problem compiling a small hello World App from the console using this command in mysys:
$ g++ hello.cpp `wx-config --libs` `wx-config --cxxflags` -o hello.exe
So here's what I tried in Netbeans:
Project properties:
C++ Compiler -> Additional Options: wx-config cxxflags (surrounded by backticks)
C++ Compiler -> Include directories: installation_Path/include
Linker -> Additional Options: wx-config --libs (surrounded by backticks)
The command lines Netbeans creates when I try to compile seem to be correct to me
g++.exe `wx-config --cxxflags` -c -g -I/D/lib/wxWidgets/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
This compiles without errors
g++.exe `wx-config --cxxflags` `wx-config --libs` -o dist/Debug/MinGW-Windows/wxwidgetstest build/Debug/MinGW-Windows/main.o -L/D/lib/wxWidgets/lib/gcc_lib
But during the linking process I get loads of errors...
Questions:
Does anybody have a working configuration for compiling wxWidgets Projects from within Netbeans and can help me out
Or does anybody see an error in the command lines could be the reason for the linking problems ?
Thank you very much!
I finally found the solution, and wrote a guide for anyone who might encounter the same problem in the future.
wxWidgets wiki: Compiling using Netbeans