MinGW problem linking to external library
This question has been asked many times: but i don't see any concrete answer anywhere. why does this happen? where is the problem? at CMake, or Compiler? or what?
I have a simple test project with GLFW library only.
The project builds and runs just fine with Visual Studio compiler selected in toolchan.
But i wanted to use MinGW instead to support debugging as well, so i switched over to that.
Now the project does not compile anymore! I installed my MinGW from sourceforge installer 64_32 bit version.
Everything works fine, as long as i dont use any external library.
The error message is "undefined reference to `glfwInit' " for all the functions my project uses from the library. so what is the problem?
switching back to Visual Studio compiler solvs the problem again.
My project test code is from GLFW example here
and in CMakeLists.txt:
`
cmake_minimum_required(VERSION 3.14)
project(test)
set(CMAKE_CXX_STANDARD 14)
#GLFW
set(GLFW3_INCLUDE_DIR C:/LIBS/GLFW/include)
set(GLFW3_LIBRARY C:/LIBS/GLFW/lib-vc2019/glfw3.lib)
include_directories(${GLFW3_INCLUDE_DIR})
add_executable(test main.cpp)
target_link_libraries(
${PROJECT_NAME}
${GLFW3_LIBRARY}
)
Please sign in to leave a comment.
I worked mine out and it was simple.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003508099-CMake-pains-cannot-get-it-to-correctly-find-a-C-Library
You say the libraries and such work fine under the visual studio compiler I believe.
But they don't work under MinGW.
This is because your libraries would have to be re made / re writen / re compiled depending on how vast they are in order to work with GCC. If you take a look at my post, I tried hard to make it work but could never get it to.
I had a look for such libraries but can't find them.
I did find this on stack overflow though which might help?: https://stackoverflow.com/questions/29378345/opengl-with-glfw-and-glew-compiling-with-gcc-on-windows
It could be that you just need to specify windows libraries as well, your perhaps better off using the visual studio compiler in this instance perhaps?
Visual studio compiler does not support debugging and that is the reason i need to use MinGW instead. I did not compile the GLFW library it's just a static lib i downloaded and then link to it.
MinGW compiler: compiles when GLFW is not included.. but not when GLFW is included
Visual Studio: compiles all and is working fine. But no debugger support with CLion..
here is the full error when MinGW is selected and i attempt to compile: sims like there is a linker error! why and how should i fix it?
Hello! According to
you're trying to link with the glfw library for Visual C++. You need to link with the glfw library for MinGW in case on MinGW. The Windows pre-compiled binaries pack from https://www.glfw.org/download.html includes this version of the library.
Also note that for MinGW only the 32-bit version of the library is available. If you need the 64-bit version, you need to use MinGW-w64.