I am running into problems when linking SDL_image in gcc 3 on cygwin under Windows 7.
I receive the following error:
/usr/lib/gcc/i686-pc-cygwin/4.3.4/../../../../i686-pc-cygwin/bin/ld: cannot find -lSDL_image
My makefile appears as this:
all: rabbit
rabbit: main.o rabbit.o renderer.o
g++ -o rabbit main.o rabbit.o renderer.o -lSDLmain -lSDL -lSDL_image
main.o: main.cpp rabbit.h
g++ -c main.cpp
rabbit.o: rabbit.cpp rabbit.h gameobject.h
g++ -c rabbit.cpp
renderer.o: renderer.cpp renderer.h
g++ -c renderer.cpp
clean:
rm -rf *o rabbit
I store SDL_image.dll, SDL_image.lib, jpeg.dll, libpng12-0.dll, libtiff-3.dll, and zlib1.dll in the directory with my executable. SDL_image.h is also in the correct location.
Please help, this has been at fault for a few days now!
SDL_image is not part of the core SDL distribution. It must be installed separately.
Check if you have /usr/local/lib/libSDL_image.a or the shared library installed.
Related
Hi I'm a beginner using libpqxx and libpq in c++. The problem I have is that it works all fine when I compile my code in Linux using my makefile. But once I try to compile it using mingw on Linux to have an executable on windows I can't make it work.
My makefile:
all: main.exe menu.o main.o option.o
main.exe: main.o menu.o option.o
g++ -o main.exe main.o menu.o option.o /usr/local/lib/libpqxx.a -lpq
option.o: option.cc option.hh
g++ -c option.cc
menu.o: menu.cc menu.hh
g++ -c menu.cc
main.o: main.cc menu.hh
g++ -c main.cc
clean:
rm *.o
rm *.exe
To compile with mingw I use:
x86_64-w64-mingw32-g++ -o main.exe main.o menu.o option.o /usr/local/lib/libpqxx.a /usr/lib/x86_64-linux-gnu/libpq.a
But I get the next error:
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
I know that these are required to compile a C++ app but what I don't know is how do I build my app so that other users won't need them. I tried to use -static flags to build but it still won't work when I remove mingw\bin\ and msys2\usr\bin\ from my path or when my friends who don't have a C++ compiler try to run it. For the record, I did include every library for the project when I asked for friends to run it.
Here's my Makefile :
rtx.exe: base.o objects.o rtx.o
g++ -O3 base.o objects.o rtx.o -o rtx -pthread -Lsrc\lib -lsfml-graphics -lsfml-window -lsfml-system -ljsoncpp -static -static-libgcc -static-libstdc++
rtx.o: rtx.cpp
g++ -Isrc\include -O3 -c rtx.cpp -static -static-libgcc -static-libstdc++
objects.o: objects.cpp objects.hpp
g++ -Isrc\include -O3 -c objects.cpp -static -static-libgcc -static-libstdc++
base.o: base.cpp base.hpp
g++ -Isrc\include -O3 -c base.cpp -static -static-libgcc -static-libstdc++
clean:
-rm *.o $(objects) rtx.exe
And here's one of the pop-op I (and my friends withour a C++ compiler) get :
There are 4 pop-ups, 2 of them being this one and the other says the same thing for libstdc++-6.dll.
I tried a bunch of things, including compiling objects.o and base.o into a library using the ar ru command but it gives the same pop-ups.
My guess is that one of the libraries I'm using, either jsonCpp or SFML is not built statically, but I couldn't find anything about how to fix it.
If you want to get rid of shared runtime libraries, you have to ensure that all your dependencies have linked the runtime statically.
SFML is by default not built with static runtime libraries, so you'll certainly have to rebuild SFML with SFML_USE_STATIC_STD_LIBS set in CMake. Similarly I assume for jsoncpp.
So, as advised by HolyBlackCat, I fully reinstalled MSYS2 and downloaded SFML and jsonCpp with mingw and after a bit of research and trial and error I ended up with this makeFile :
rtx.exe: base.o objects.o rtx.o
g++ -O3 base.o objects.o rtx.o -o rtx -pthread -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -ljsoncpp -static
rtx.o: rtx.cpp
g++ -Isrc\include -O3 -c rtx.cpp -DSFML_STATIC -static
objects.o: objects.cpp objects.hpp
g++ -Isrc\include -O3 -c objects.cpp -DSFML_STATIC -static
base.o: base.cpp base.hpp
g++ -Isrc\include -O3 -c base.cpp -DSFML_STATIC -static
clean:
-rm *.o $(objects) rtx.exe
And now, it does make a static build.
I'm currently trying to use a makefile to automate my build process which I am still new to. When I run the g++ command:
g++ -I includes -L lib -lSDL2_test -lSDL2 -lSDL2main main.o -o main.exe
from the following makefile:
main: main.o
g++ -I includes -L lib -lSDL2_test -lSDL2 -lSDL2main main.o -o main.exe
main.o: main.cpp
g++ -c main.cpp
I get clang: error: linker command failed with exit code 1
However when running the same g++ command from the same directory as the makefile everything compiles correctly and I don't get the error. So how do I fix this?
EDIT:
I've done some testing and found out the problem with the makefile is that the -I includes g++ flag is not enabling the main.o file to find SDL.H, hopefully that helps to narrow down the problem.
#G.M's comment isn't unrelated - it's the correct answer to the problem. The include files are needed during the compile stage (the main.o: main.cpp rule), NOT during the link stage (i.e. the main: main.o rule.)
Move the -I includes flag to the second rule, and try again.
I'm trying to get a C++ program that uses XWindows to build on Bash on Ubuntu on Windows. I understand that Bash on Ubuntu on Windows does not officially support graphical Linux applications, but I would like the program to build regardless if possible. I have tried to reduce my issue as much as possible, hopefully I have provided enough information.
First, I installed the libx11-dev package and the packages associated with it using the command:
sudo apt-get install libx11-dev
Second, my Makefile is the following:
CXX = g++
CXXFLAGS = -Wall -MMD -lX11
EXEC = exe
OBJECTS = main.o window.o
DEPENDS = ${OBJECTS:.o=.d}
${EXEC}: ${OBJECTS}
${CXX} ${CXXFLAGS} ${OBJECTS} -o ${EXEC}
-include ${DEPENDS}
.PHONY: clean
clean:
rm ${EXEC} ${OBJECTS} ${DEPENDS}
Third, the window.h file is the following:
#ifndef __WINDOW_H__
#define __WINDOW_H__
#include <X11/Xlib.h>
class Xwindow {
Display *d;
public:
Xwindow();
};
#endif
Fourth the window.cc file is the following:
#include "window.h"
Xwindow::Xwindow() {
d = XOpenDisplay(NULL);
}
Finally the main.cc file is the following:
#include "window.h"
int main() {
Xwindow xw();
return 0;
}
When I run my Makefile I get the following output:
g++ -Wall -MMD -lX11 -c -o main.o main.cc
g++ -Wall -MMD -lX11 -c -o window.o window.cc
g++ -Wall -MMD -lX11 main.o window.o -o exe
window.o: In function `Xwindow::Xwindow()':
window.cc:(.text+0x12): undefined reference to `XOpenDisplay'
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'exe' failed
make: *** [exe] Error 1
Any help is appreciated.
In some environments, including Ubuntu, you need to pass -l arguments after the object files that use these libraries.
Also, -l don't belong in CXXFLAGS, they should be in LIBS which goes after ${OBJECTS}.
I am trying to compile a game using g++ and the SFML library. It works fine on Linux, but when I try to compile on Windows, the cmd floods me with error messages that all start with "player.o:player.cpp:(.text+xxxxxx):undefined reference to _imp___..."
My makefile looks like this:
all:
main.o player.o simplefunctions.o
g++ -std=c++11 main.o player.o simplefunctions.o -o climb -L C:/SFML-2.3.1/lib -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network
main.o: main.cpp
g++ -std=c++11 -c main.cpp -I C:/SFML-2.3.1/include
player.o: player.cpp
g++ -std=c++11 -c player.cpp -I C:/SFML-2.3.1/include
simplefunctions.o: simplefunctions.cpp
g++ -std=c++11 -c simplefunctions.cpp -I C:/SFML-2.3.1/include
.cpp -I C:/SFML-2.3.1/include
The only difference between this and my makefile I use for the same program on ubuntu is the -I and -L tags to include the library, which I don't need on linux since it gets included automatically. All the appropriate header files are also included in the appropriate cpp's.