I was trying the example code on "How to Play Media Files with Media Foundation", and I tried to compile the code with the following makefile:
LDFLAGS = -LC:\\pathToWindowsSDK\\Lib\\10.0.22000.0\\um\\x64 -lMfplat -lMfuuid -lUser32 -lOle32 -lShlwapi -lMf
default: winmain.o player.o
g++ winmain.o player.o -o a.exe
winmain.o: winmain.cpp player.h
g++ winmain.cpp -c
player.o: player.cpp player.h
g++ player.cpp $(LDFLAGS) -c
and I keep getting the following undefined references:
C:/Personal/Soft/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: player.o:player.cpp:(.rdata$.refptr.GUID_NULL[.refptr.GUID_NULL]+0x0): undefined reference to `GUID_NULL'
C:/Personal/Soft/mingw/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: player.o:player.cpp:(.rdata$.refptr.MR_VIDEO_RENDER_SERVICE[.refptr.MR_VIDEO_RENDER_SERVICE]+0x0): undefined reference to `MR_VIDEO_RENDER_SERVICE'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:4: default] Error 1
Both are undefined errors of GUID, is there a library that I should link?
I'm using MSYS g++ compiler, and Windows 11 SDK (10.0.22000). Thanks in advance!
Try adding -luuid (Visual C++ projects created through Visual Studio link to uuid.lib by default).
Related
gcc core_basic_window.c -o game.exe -o1 -Wall -std=c99 -Wno-missing-braces -I include/ -L Iraylib -Iopeng132 -Igdi32 -Iwinmm
D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x37): undefined reference to InitWindow' D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x43): undefined reference to SetTargetFPS'
D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x4a): undefined reference to BeginDrawing' D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0x72): undefined reference to ClearBackground'
JZC.o:core_basic_window.c:(.text+0xc4): undefined reference to EndDrawing' D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0xc9): undefined reference to WindowShouldClose'
D:\w64devkit\bin/ld.exe: C:\Users\dy.kim\AppData\Local\Temp\cc8gmJZC.o:core_basic_window.c:(.text+0xd9): undefined reference to `CloseWindow'
collect2.exe: error: ld returned 1 exit status
it won't work...
I am using vscode and putted all task.
vscode will say that it isn't defined.
Your command:
gcc core_basic_window.c -o game.exe -o1 -Wall -std=c99 -Wno-missing-braces -I include/ -L Iraylib -Iopeng132 -Igdi32 -Iwinmm
Contains a lot of typos, and contains -Is where -ls are required. The following compiles for me:
g++ main.cpp -I"Path_to_Raylib" -L"Path_to_Raylib" -lraylib -lopengl32 -lgdi32 -lwinmm
Given my system's file structure, I would write the following:
g++ main.cpp -I"C:\raylib\raylib-4.0.0_win64_mingw-w64\include" -L"C:\raylib\raylib-4.0.0_win64_mingw-w64\lib" -lraylib -lopengl32 -lgdi32 -lwinmm
If you want to use C, you would obviously change g++ to gcc and you would add things like -o if you want a specific name for your output file.
I hope this was helpful.
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
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 ?
(Hello, this is my first post, and I am using Dev C++ IDE 5.11)
I included the header, SOIL.h and the linker: -lSOIL.
This program compiles with no problem and runs correctly, but when I add any function into my code from the SOIL library, I receive a linker error.
'recipe for target 'Project1.exe' failed'
Here is the code from SOIL that causes the linker error:
unsigned char* image = SOIL_load_image("container.jpg", &width, &height, 0, SOIL_LOAD_RGB);
(There is probably an easy explanation and answer for this, but I have searched everywhere as I cannot find it.)
Note: I am following a tutorial from the website learnopengl
Here is my makefile.win:
# Project: Project1
# Makefile created by Dev-C++ 5.11
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
OBJ = Untitled2.o
LINKOBJ = Untitled2.o
LIBS = -L"D:/Dev-Cpp/MinGW32/lib" -L"D:/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lopengl32 -lopengl32 -lmingw32 -lSOIL
INCS = -I"D:/Dev-Cpp/MinGW32/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include"
CXXINCS = -I"D:/Dev-Cpp/MinGW32/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include" -I"D:/Dev-Cpp/MinGW32/lib/gcc/mingw32/4.7.2/include/c++"
BIN = Project1.exe
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm.exe -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)
Untitled2.o: Untitled2.cpp
$(CPP) -c Untitled2.cpp -o Untitled2.o $(CXXFLAGS)
Compilation log:
Compiling project changes...
--------
- Project Filename: D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Project1.dev
- Compiler Name: MinGW GCC 4.7.2 32-bit Release
Building makefile...
--------
- Filename: D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win
Processing makefile...
--------
- Makefile Processor: D:\Dev-Cpp\MinGW32\bin\mingw32-make.exe
- Command: mingw32-make.exe -f "D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win" all
g++.exe Untitled2.o -o Project1.exe -L"D:/Dev-Cpp/MinGW32/lib" -L"D:/Dev-Cpp/MinGW32/mingw32/lib" -static-libstdc++ -static-libgcc -lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32 -lopengl32 -lmingw32 -Bstatic -lSOIL
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x3e): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x72): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xbe): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xf2): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x115): undefined reference to `glGetString#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x15e): more undefined references to `glGetString#4' follow
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1d1): undefined reference to `wglGetProcAddress#4'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x5e2): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x66a): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x84f): undefined reference to `glDeleteTextures#8'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0xdf8): undefined reference to `glReadPixels#28'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x100d): undefined reference to `glGetIntegerv#8'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x1427): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x15a8): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x161a): undefined reference to `glTexImage2D#36'
D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o):SOIL.c:(.text+0x188c): undefined reference to `glTexImage2D#36'
d:/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: D:/Dev-Cpp/MinGW32/lib/libSOIL.a(SOIL.o): bad reloc address 0x0 in section `.data'
d:/dev-cpp/mingw32/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
D:\Desktop Files\Programming Stuff\C++\C++ Projects\project examples\etchasketch\Makefile.win:25: recipe for target 'Project1.exe' failed
mingw32-make.exe: *** [Project1.exe] Error 1
Compilation results...
--------
- Errors: 1
- Warnings: 0
- Compilation Time: 0.25s
Thank you so much Patrick Stewart for helping me figure this out.
Oddly enough, when I didn't have the -Bstatic, there was the only one error. When I followed what you said about the compilation log, it gave more errors that I did not know were there. I Googled it and found out an answer from this site: http://www.gamedev.net/topic/614336-soil-linker-errors/
that the -lSOIL had to be before the -lopengl32.
This is weird in my opinion, but it is a solution.
I'm having quite a bit of trouble linking a test project of FLTK I'm doing on Code::Blocks, Windows 7.
After spending quite a lot of time understanding how to put the libraries in the correct order, I managed to get the project nearly done. However there's still a linking problem:
mingw32-g++.exe -Wall -fexceptions -IC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0 -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib -mwindows -lfltk -lole32 -luuid -lcomctl32
C:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib/libfltk.a(Fl_Native_File_Chooser.o):Fl_Native_File_Chooser.cxx:(.text+0x1556): undefined reference to `__chkstk_ms'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
1 errors, 0 warnings
However, using the same exact script that Code::Blocks shows, executed on command prompt ( or even msys for what matters ), correctly compiles and links everything. The resulting exe also works.
C:\Users\Svalorzen\Documents\Projects\test>mingw32-g++ -Wall -fexceptions -IC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0 -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -c C:\Users\Svalorzen\Documents\Projects\test\main.cpp -o obj\Debug\main.o
C:\Users\Svalorzen\Documents\Projects\test>mingw32-g++ -o bin\Debug\test.exe obj\Debug\main.o -LC:\Users\Svalorzen\Documents\Projects\fltk-1.3.0\lib -mwindows -lfltk -lole32 -luuid -lcomctl32
C:\Users\Svalorzen\Documents\Projects\test>dir bin\Debug\test.exe
Volume in drive C has no label.
Volume Serial Number is 00E8-6659
Directory of C:\Users\Svalorzen\Documents\Projects\test\bin\Debug
10/05/2012 19:01 661.087 test.exe
1 File(s) 661.087 bytes
0 Dir(s) 66.016.849.920 bytes free
The paths in the instruction are all absolute, so I don't really understand why this is.
What am I doing wrong? What I should check?
EDIT: It turned out that I had a MinGW installation I didn't remember about and Code::Blocks was using that one. I changed it and now everything is fixed.
If your MinGW is up-to-date, then try adding -no-vcproj and -no-dsp and then run mingw32-make confclean.
It turned out that I had a MinGW installation I didn't remember about and Code::Blocks was using that one.
I setup Code::Blocks with the same compiler that created the library and now everything is fine.