GLFW MinGW link error - c++

I've been attempting to test out GLFW with C++ for quite a while and am having constant linker issues. I am fairly new to C++, although I have experience in Java and C#, working directly with the compiler is fairly new to me. Here's my setup information.
IDE: Qt Creator
OS: Windows 7 64-bit
Compiler: MinGW32 4.8.1
01:23:26: Starting: "C:\MinGW\bin\mingw32-make.exe"
C:/MinGW/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'A:/workspace_cpp/Test-Debug'
g++ -Wl,-subsystem,console -mthreads -o debug\Test.exe debug/main.o -lglfw3 -lopengl32
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.::(.text+0x2c7): undefined reference to `CreateDCW#16'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x358): undefined reference to `GetDeviceCaps#8'
Makefile.Debug:77: recipe for target 'debug\Test.exe' failed
mingw32-make[1]: Leaving directory 'A:/workspace_cpp/Test-Debug'
Makefile:34: recipe for target 'debug' failed
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x370): undefined reference to `GetDeviceCaps#8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor .c:(.text+0x39e): undefined reference to `DeleteDC#4'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj): bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
The code I'm testing is the code on the GLFW Documentation Page, I'm using my own build of GLFW, and have already tried this and several other potential solutions. I have tried using the prebuilt GLFW mingw libraries but I couldn't get them to work.

The solution as posted by enhzflep was to include to gdi32 library when compiling, making all the necessary linkers -lglfw3 -lgdi32 -lopengl32, as the missing methods, CreateDCW, GetDeviceCaps and DeleteDC are all inside of libgdi32.a in the MinGW lib folder C:\MinGW\lib\libgdi32.a in this case.

Related

I'm trying to figure out what this error is that I am getting: "cannot find -lmingw32"

I'm trying to setup SDL graphics for my project, and I tried to run it after I was almost complete, but then I got this error:
g++ -o dist/Debug/Cygwin-Windows/project_2_snake build/Debug/Cygwin-Windows/main.o -L../../../../../../../../../SDL2/lib -lmingw32 -lsdl2main -lsdl2
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status
make[2]: *** [nbproject/Makefile-Debug.mk:63: dist/Debug/Cygwin-Windows/project_2_snake.exe] Error 1
Can anyone could help me with this?
Additional information
windows 10 i think
Cygwin c++ compiler
Your linker does not know where to find the library you are referencing.
You will have to tell it where to find it. The easiest solution would likely be to add the libs directories of the libraries you are referencing to your linker's search directories.

Can't compile with CMake and ncurses

I'm aware similar questions have been posted, but I can't see how they relate to my case. I will preface this question by saying I'm not very familiar with CMake, so it's entirely possible this is a quick fix and I just don't see it!
I am collaborating on a project, and yesterday my teammate added the ncurses library to the project to build a terminal GUI. Ever since ncurses was added, I haven't been able to compile my project. However, I did install all 6 ncurses-* packages, so it should behave with my machine.
I have pulled down the latest version of the master branch from our GitHub repo, which compiles and runs perfectly on his machine. However it won't even compile on mine.
System:
Linux Mint 18.1 Cinnamon
CMake Version 3.5.1
Things I've tried:
I deleted CMakeCache.txt and reloaded it
I deleted my entire CMake build directory and redid make
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(irc)
set(SHARED_FLAGS " -Wall -Wextra -Wshadow -Werror -g -D_POSIX_C_SOURCE=200809L -lncurses")
set(CMAKE_C_FLAGS "-std=c11 ${SHARED_FLAGS}")
set(CMAKE_CXX_FLAGS "-std=c++11 ${SHARED_FLAGS}")
include_directories(include)
add_library(client_core SHARED src/client/irc_client.c)
add_executable(client src/client/irc_client_gui.c)
add_executable(server src/server/irc_server.c)
// SOLUTION - MISSING LINE
target_link_libraries(client ncurses)
install(FILES include/irc_client.h DESTINATION include)
install(FILES include/irc_server.h DESTINATION include)
CMakeOutput:
CMakeFiles/client.dir/src/client/irc_client_gui.c.o: In function `main':
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:17:
undefined reference to `initscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:18:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:19:
undefined reference to `mvprintw'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:21:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:21:
undefined reference to `wgetnstr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:22:
undefined reference to `LINES'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:22:
undefined reference to `mvprintw'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:23:
undefined reference to `stdscr'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:23:
undefined reference to `wgetch'
/home/chrisjansson/Documents/irc/src/client/irc_client_gui.c:24:
undefined reference to `endwin'
collect2: error: ld returned 1 exit status
CMakeFiles/client.dir/build.make:94: recipe for target 'client' failed
make[2]: *** [client] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/client.dir/all'
failed
make[1]: *** [CMakeFiles/client.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Interestingly enough, if I copy/paste irc_client_gui.c somewhere else on my machine, compile it manually with gcc and run it, it works perfectly. So the issue isn't my machine, it's something with CMake trying to compile my entire project. Any ideas? Thanks so much!
The solution is to add a line like this:
target_link_libraries(client ncurses)
This tells CMake that when it is linking the client target, it should use the -lncurses option to link in the ncurses library.

Encounter errors when compiling program using QT5.6 on windows 10

I want to compile a program called uartassistant using QT5.6 on windows 10,I encountered this error:
g++ -Wl,-subsystem,windows -mthreads -o debug\uartassistant.exe
debug/main.o debug/dialog.o debug/hled.o debug/moc_dialog.o
debug/moc_hled.o -lmingw32 -LF:\qt\5.6\mingw49_32\lib
F:\qt\5.6\mingw49_32\lib\libqtmaind.a -LC:\utils\postgresql\pgsql\lib
-LC:\utils\my_sql\my_sql\lib -lshell32 -LE:\uartassistannew\uartassistant\build -lqextserialportd1 -LE:\uartassistannew\uartassistant\analogwidgets -lanalogwidgets F:\qt\5.6\mingw49_32\lib\libQt5Widgetsd.a
F:\qt\5.6\mingw49_32\lib\libQt5Quickd.a
F:\qt\5.6\mingw49_32\lib\libQt5Guid.a
F:\qt\5.6\mingw49_32\lib\libQt5Qmld.a
F:\qt\5.6\mingw49_32\lib\libQt5Networkd.a
F:\qt\5.6\mingw49_32\lib\libQt5Cored.a
E:\uartassistannew\uartassistant\analogwidgets/libanalogwidgets.a(manometer.o):manometer.cpp:(.text+0x44a):
undefined reference to _imp___ZNK7QString3argEdiciRK5QChar'
E:\uartassistannew\uartassistant\analogwidgets/libanalogwidgets.a(manometer.o):manometer.cpp:(.text+0x11f8):
undefined reference to_imp___ZNK7QString3argEdiciRK5QChar'
E:\uartassistannew\uartassistant\analogwidgets/libanalogwidgets.a(manometer.o):manometer.cpp:(.text+0x1570):
undefined reference to _imp___ZNK11QMetaObject2trEPKcS1_'
E:\uartassistannew\uartassistant\analogwidgets/libanalogwidgets.a(manometer.o):manometer.cpp:(.text+0x178a):
undefined reference to_imp___ZNK11QMetaObject2trEPKcS1_'
F:/qt/Tools/mingw492_32/bin/../lib/gcc/i686-w64-mingw32/4.9.2/../../../../i686-w64-mingw32/bin/ld.exe:
E:\uartassistannew\uartassistant\analogwidgets/libanalogwidgets.a(manometer.o):
bad reloc address 0x24 in section
`.text$ZplRK7QStringS1[__ZplRK7QStringS1_]' collect2.exe: error: ld
returned 1 exit status Makefile.Debug:71: recipe for target
'debug\uartassistant.exe' failed mingw32-make[1]: *
[debug\uartassistant.exe] Error 1 mingw32-make[1]: Leaving directory
'E:/uartassistannew/build-uartassistant-Desktop_Qt_5_6_0_MinGW_32bit-Debug'
makefile:34: recipe for target 'debug' failed mingw32-make: *
[debug] Error 2 Error while building/deploying project uartassistant
(kit: Desktop Qt 5.6.0 MinGW 32bit) When executing step "Make"
12:14:13: Elapsed time: 00:18.
I compiled the same program on windows 7 using QT,no error happened.
Anyone can help me deal with it?
Thanks.

Linker error while building from source code

I am trying to build an application from source. I am able to configure it using 'cmake .'. However, when I run 'make' it gives me this:
Linking CXX executable ../../bin/lux64/Release/od_batch_launcher
../../bin/lux64/Release/libBasic.so: undefined reference to `dlopen'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlclose'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlerror'
../../bin/lux64/Release/libBasic.so: undefined reference to `dlsym'
../../bin/lux64/Release/libBasic.so: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/lux64/Release/od_batch_launcher] Error 1
make[1]: *** [src/Basic/CMakeFiles/od_batch_launcher.dir/all] Error 2
make: *** [all] Error 2
I understand that its is unable to dynamically link to a c++ library. I don't quite know how to make the necessary changes to cmake. I am running gcc version: 4.9.2 on Linux Mint 17. I would be grateful for any help. Thank you!
Try passing -DCMAKE_EXE_LINKER_FLAGS=-ldl to the CMake executable. To change the CMake build scripts, add something like:
target_link_libraries(target_name dl)
where target_name is basically the executable name without any extensions (e.g. .exe).
EDIT: Actually, I just reread you question, and I'm putting this in the wrong place. You really want:
target_link_libraries(Basic dl)
Apparently, there were also pthread-related errors, so you'd also have to add:
target_compile_options(Basic PUBLIC -pthread)
Both of these go in whichever file contains add_library(Basic) (usually CMakeLists.txt).
EDIT 2: Instead of target_compile_options, try:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")

Compiling c++ with Armadillo library at NeatBeans

I am going to compile C++ program which contains Armadillo library.
This issue is feasible via command line with this command:
g++ '/arm.cpp' -o example -O1 -larmadillo
But when I add -O1 -larmadillo to the compile options of my NetBeans project I get a considerable amount of errors.
I got these errors:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/atx/NetBeansProjects/armadillo'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/armadillo
make[2]: Entering directory `/home/atx/NetBeansProjects/armadillo'
mkdir -p dist/Debug/GNU-Linux-x86
g++ -O3 -o dist/Debug/GNU-Linux-x86/armadillo build/Debug/GNU-Linux-x86/main.o
build/Debug/GNU-Linux-x86/main.o: In function `gemv<double>':
/usr/include/armadillo_bits/blas_wrapper.hpp:79: undefined reference to `wrapper_dgemv_'
/usr/include/armadillo_bits/blas_wrapper.hpp:79: undefined reference to `wrapper_dgemv_'
/usr/include/armadillo_bits/blas_wrapper.hpp:79: undefined reference to `wrapper_dgemv_'
/usr/include/armadillo_bits/blas_wrapper.hpp:79: undefined reference to `wrapper_dgemv_'
build/Debug/GNU-Linux-x86/main.o: In function `gemm<double>':
/usr/include/armadillo_bits/blas_wrapper.hpp:114: undefined reference to `wrapper_dgemm_'
/usr/include/armadillo_bits/blas_wrapper.hpp:114: undefined reference to `wrapper_dgemm_'
/usr/include/armadillo_bits/blas_wrapper.hpp:114: undefined reference to `wrapper_dgemm_'
/usr/include/armadillo_bits/blas_wrapper.hpp:114: undefined reference to `wrapper_dgemm_'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/armadillo] Error 1
make[2]: Leaving directory `/home/atx/NetBeansProjects/armadillo'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/atx/NetBeansProjects/armadillo'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 136ms)
Looks like your Armadillo installation is incomplete, or you have two versions of Armadillo installed. I recommend that you manually uninstall any previous versions of Armadillo (both the includes and the run-time library) and then do a fresh install, using a freshly downloaded Armadillo .tar.gz package: http://arma.sourceforge.net/download.html
Alternatively, you can work around the issue you're having. Edit "include/armadillo_bits/config.hpp" and comment out the line with ARMA_USE_WRAPPER. Then, instead of linking with -larmadillo, link with -lblas -llapack
I know this was an old question, but I had troubles recently with this so I want to help if someone else encounters same problems as I did. This is how-to setup Armadillo library in NetBeans C++ on 64 bit Windows 7.
Download the latest version of Armadillo from http://arma.sourceforge.net/download.html
Unpack it in some directory, where ever you want.
Go to Netbeans -> Project Properties -> C++ Compiler
3.1 Include Directories -> find your Armadillo directory and select folder "include".
3.2 Preprocessor Definitions -> ARMA_USE_LAPACK ARMA_USE_BLAS
Go to Netbeans -> Project Properties -> Linker
4.1 Additional Library Directories -> find your Armadillo directory and select folder "examples/lib_win64".
4.2 Additional Dependencies -> lapack_win64_MT.lib blas_win64_MT.lib
Go to your project's folder and add files from Armadillo/examples/lib_win64. 4 files should be added -> blas_win64_MT.dll, blas_win64_MT.lib, lapack_win64_MT.dll and lapack_win64_MT.lib.
This should be it. Now you can use Armadillo library in C++, just add in your cpp #include and if you want using namespace arma;
I hope this was helpful! Cheers!