I'm trying to build RecastNavigation via MinGW, everything seems builds just fine except RecastDemo application.
I've done:
cmake -G"MSYS Makefiles" -DSDL_INCLUDE_DIR:PATH=/c/_libdist/x86/msys/include/SDL \
-DSDL_LIBRARY:PATH=/c/_libdist/x86/msys/lib/libSDL.a \
-DSDLMAIN_LIBRARY:PATH=/c/_libdist/x86/msys/lib/libSDLMain.a ..
then make VERBOSE=1 gives me this at the end (cut out bunch of undefines):
cd /C/_lib/blackberry/RecastNavigation/build.msys/RecastDemo && /C/app/MinGW/bin/g++.exe -O3 -DNDEBUG -mwindows -Wl,
--whole-archive CMakeFiles/RecastDemo.dir/objects.a -Wl,--no-whole-archive -o ../../RecastDemo/Bin/RecastDemo.exe -Wl,-
-out-implib,../../RecastDemo/Bin/libRecastDemo.dll.a -Wl,--major-image-version,0,--minor-image-version,0 ../DebugUtils/
libDebugUtils.a ../Detour/libDetour.a ../DetourCrowd/libDetourCrowd.a ../DetourTileCache/libDetourTileCache.a ../Recast/
libRecast.a /c/_libdist/x86/msys/lib/libSDL.a /c/_libdist/x86/msys/lib/libSDLMain.a -lglu32 -lopengl32 -lkernel32 -luser
32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
Creating library file: ../../RecastDemo/Bin/libRecastDemo.dll.a
c:/_libdist/x86/msys/lib/libSDL.a(SDL_systimer.o): In function `SDL_StartTicks':
c:\_lib\SDL\1.2.15/./src/timer/win32/SDL_systimer.c:67: undefined reference to `timeBeginPeriod#4'
c:\_lib\SDL\1.2.15/./src/timer/win32/SDL_systimer.c:68: undefined reference to `timeGetTime#0'
c:/_libdist/x86/msys/lib/libSDL.a(SDL_systimer.o): In function `SDL_GetTicks':
...
...
...
c:/app/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function `main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain#16'
collect2: ld returned 1 exit status
make[2]: *** [../RecastDemo/Bin/RecastDemo.exe] Error 1
I'm not sure where to explore more as library order seems correct. What am i missing here?
The problem is you are missing a link library, mingw32 in this case. The easiest way to fix it is to tell CMake where to find SDL. You can do this by setting the SDLDIR environment variable (see http://cmake.org/cmake/help/v2.8.10/cmake.html#module:FindSDL). So based on your SDL install location, from your MinGW prompt:
export SDLDIR=/c/_libdist/x86/msys
Then run CMake:
cmake -G "MSYS Makefiles" ..
This should find SDL and set the SDL include directories and link libraries correctly.
However, there is a bug in CMake that passes libraries to the linker in the wrong order, see http://public.kitware.com/Bug/view.php?id=13769. The bug has been fixed but isn't in the latest release yet (2.8.10.2).
Until there's a new CMake release what you can do is edit the cached
SDL_LIBRARY value in CMakeCache.txt in your build directory and switch
the order of the SDL libraries around then run CMake again.
Related
I'm trying to compile the code found in https://www.glfw.org/documentation. This code is in "main.cpp" and I have a folder in the same directory called "dependencies" containing: "glfw3.h", "glfw3.lib" and "libglfw3.a".
project directory
dependencies
I go to the directory in powershell and run:
g++ main.cpp -ldependencies .\dependencies\libglfw3.a -lopengl32 -lgdi32
and it returns:
c:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ldependencies: No such file or directory
collect2.exe: error: ld returned 1 exit status
What have I done wrong?
I've looked all the internet for solutions but none have worked even when I exactly do what is shown on the tutorial or solution, im quite stuck. I think its because im attempting to do this without an IDE (I used visual studio) and until recently i've only did C++ development with an IDE and i'm inexperienced with compiling and linking outside of IDE's.
g++ main.cpp -ldependencies .\dependencies\libglfw3.a -lopengl32 -lgdi32
should be
g++ main.cpp -Ldependencies -lglfw3 -lopengl32 -lgdi32
-L for a directory to search, -l for the name of the library to link with.
I am building a Qt application (with CMake) that will capture and analyze some network packets. Since I am using C++ all over the project, it would be convenient for me to use Pcap++ in my application rather than using lower lever C APIs provided by libs such as libpcap or winpcap.
However I find it hard to use pre-built Pcap++ libraries in my CMakeLists.txt given that no much info was provided on how such an integration would look like.
The application is supposed to be cross-platform and I started with integrating Pcap++ on windows first. So I have downloaded pre-built pcapplusplus-22.05-windows-mingw32-gcc-9.2.0. And then tried to follow instructions from Readme and apply them to my CMake file.
I post here the relevant parts of CMakeLists to show how I have attempted to do it:
set(THIRD_PARTY_LIBS "")
set(THIRD_PARTY_INCLUDES "")
# Add Pcap++ headers
list(APPEND THIRD_PARTY_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/header)
# Pcap++ libs and dependencies according to their README
list(APPEND THIRD_PARTY_LIBS pthread ws2_32 iphlpapi)
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Common++.lib)
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Packet++.lib)
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Pcap++.lib)
# Add WinPcap libs
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/WpdPack/Lib/Packet.lib ${CMAKE_CURRENT_LIST_DIR}/WpdPack/Lib/wpcap.lib)
# Add includes to project
include_directories(${THIRD_PARTY_INCLUDES})
# Add libs to project
target_link_libraries(${PROJECT_NAME} PRIVATE ${THIRD_PARTY_LIBS} Qt${QT_VERSION_MAJOR}::Core)
The relative locations are fine. Yet, when application is linking, the following error is occurring:
cmd.exe /C "cd . && C:\Qt\Tools\mingw1120_64\bin\c++.exe -g -mwindows CMakeFiles/MyProjectName.dir/MyProjectName_autogen/mocs_compilation.cpp.obj CMakeFiles/MyProjectName.dir/src/core/AppLogger.cpp.obj CMakeFiles/MyProjectName.dir/src/main.cpp.obj CMakeFiles/MyProjectName.dir/src/utils/utils.cpp.obj CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj CMakeFiles/MyProjectName.dir/res/win.rc.obj CMakeFiles/MyProjectName.dir/MyProjectName_autogen/PNK5WDWK6L/qrc_resources.cpp.obj -o MyProjectName.exe -Wl,--out-implib,libMyProjectName.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L<proj_loc>/src/core -L<proj_loc>/src/utils -L<proj_loc>/ui thirdparty/spdlog/libspdlogd.a ../../thirdparty/WpdPack/Lib/Packet.lib ../../thirdparty/WpdPack/Lib/wpcap.lib -lpthread -lws2_32 -liphlpapi ../../thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Common++.lib ../../thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Packet++.lib ../../thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Pcap++.lib C:/Qt/6.3.1/mingw_64/lib/libQt6Network.a C:/Qt/6.3.1/mingw_64/lib/libQt6Widgets.a -lws2_32 C:/Qt/6.3.1/mingw_64/lib/libQt6Gui.a C:/Qt/6.3.1/mingw_64/lib/libQt6Core.a -lmpr -luserenv -lmingw32 C:/Qt/6.3.1/mingw_64/lib/libQt6EntryPoint.a -lshell32 -ld3d11 -ldxgi -ldxguid -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj:<proj_loc>/thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/header/pcappp/PcapLiveDeviceList.h:47: undefined reference to `pcpp::PcapLiveDeviceList::~PcapLiveDeviceList()'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj: in function `MainWindow::on_pushButton_StartRecording_clicked()':
<proj_loc>/ui/mainwindow.cpp:36: undefined reference to `pcpp::PcapLiveDeviceList::getPcapLiveDeviceByIp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj: in function `pcpp::PcapLiveDeviceList::getInstance()':
<proj_loc>/thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/header/pcappp/PcapLiveDeviceList.h:47: undefined reference to `pcpp::PcapLiveDeviceList::PcapLiveDeviceList()'
collect2.exe: error: ld returned 1 exit status
In my application I am executing this simple function to get a network adapter by it's IP address:
this->dev = = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIp("1.2.3.4")
Seeing "undefined reference to" makes me think that my libs were not properly included. How do I properly do it?
Later edit: It seems my application is 64bit but the libraries are 32bit compiled. This is probably my issue. However I am wondering why no warnings are visible to indicate this
On their website it is clearly stated that they don't support MinGW 64-bit compilation:
"Please notice that x64 compilation is not supported (and will not work) on either MinGW32 nor MinGW-w64!"
Therefore there is no way to link it within my 64bit application that uses MinGW.
There seems to be a bunch of similar questions to this one but they all seem to have answered that aren't related to what I'm doing.
I've been working on a C++ project using Ogre3D for over a year and I'm currently trying to add support for playing videos. I found a suitable library that uses ogre and ffmpeg to play the videos which I'm now trying to incorporate into our build system. Project uses mingw and cmake.
I've managed to compile the video library (https://github.com/scrawl/ogre-ffmpeg-videoplayer) and I managed to link it just fine with the my project.
The problem arises during linking of the main project, it complains about undefined references to basic ogre functions that we're working fine before. It points to lines of code in the new video library where the failing reference occurs.
The video library relies on ogre and ffmpeg, initially i got undefined references to ffmpeg functions but after managing to link the ffmpeg libraries with my main project those errors went away, so I don't understand the current undefined ogre references.
One thing that might be of note is that when the video library is compiling, the g++ commands does not reference ogre or ffmpeg even though the cmake files are calling target_link_libraries on them. This is a bit strange to me, but again probably just a lack of linking understanding on my part since it compiles fine.
Here's the full build log with the main linking error: http://pastebin.com/X6Lbccag
the offending lines from there:
C:\mingw\bin\g++.exe -std=c++0x -msse2 -Wno-unused-function -g -Wl,--whole-archive CMakeFiles\RunTests.dir/objects.a -Wl,--no-whole-archive -o RunTests.exe -Wl,--out-implib,libRunTests.dll.a -Wl,--major-image-version,0,--minor-image-version,0 libThrive.a contrib\googletest\libgtest_main.a C:\mingw\install\lib\libboost_thread-mt.dll C:\mingw\install\lib\libboost_date_time-mt.dll C:\mingw\install\lib\libboost_system-mt.dll C:\mingw\install\lib\libboost_chrono-mt.dll C:\mingw\install\lib\libboost_filesystem-mt.dll C:\mingw\OgreSDK\lib\Debug\libOgreMain_d.dll.a C:\mingw\install\lib\libboost_thread-mt.dll C:\mingw\install\lib\libboost_date_time-mt.dll C:\mingw\install\lib\libboost_system-mt.dll C:\mingw\install\lib\libboost_chrono-mt.dll C:\mingw\install\lib\libboost_filesystem-mt.dll C:\mingw\OgreSDK\lib\Debug\libOgreMain_d.dll.a C:\mingw\OgreSDK\lib\Debug\libOIS_d.dll.a C:\mingw\install\lib\libBulletDynamics_Debug.a C:\mingw\install\lib\libBulletCollision_Debug.a C:\mingw\install\lib\libLinearMath_Debug.a C:\mingw\install\lib\libBulletSoftBody_Debug.a C:\mingw\install\lib\libCEGUIBase-9999_d.dll.a C:\mingw\install\lib\libCEGUIOgreRenderer-9999_d.dll.a C:\mingw\install\lib\libtinyxml.a C:\mingw\install\lib\Debug\libogre-ffmpeg-videoplayer.a C:\mingw\install\lib\libavcodec.dll.a C:\mingw\install\lib\libavformat.dll.a C:\mingw\install\lib\libavutil.dll.a C:\mingw\install\lib\libswscale.dll.a C:\mingw\install\lib\libswresample.dll.a contrib\luabind\src\libluabind.a contrib\lua\liblua.dll.a -lm C:\mingw\install\bin\libcAudio.dll contrib\googletest\libgtest.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
C:\mingw\install\lib\Debug\libogre-ffmpeg-videoplayer.a(videostate.cpp.obj): In function `ZN5Video10VideoState4initERKSs':
C:/mingw/temp/ffmpeg/ogre-ffmpeg-videoplayer-master/src/videostate.cpp:617: undefined reference to `Ogre::ResourceGroupManager::openResource(std::string const&, std::string const&, bool, Ogre::Resource*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [RunTests.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/RunTests.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
You'll notice that libOgreMain_d.dll.a is linked in the failing command which is what contains the referenced Ogre::ResourceGroupManager::openResource function (i confirmed this by finding the function in the semi-scrambled libOgreMain_d.dll.a). The cmakelists.txt: http://pastebin.com/LVsJtxny
Here's the compilation log from the video library: http://pastebin.com/k3jLiL09
and it's cmakelists.txt: https://github.com/scrawl/ogre-ffmpeg-videoplayer/blob/master/CMakeLists.txt
My first thought that perhaps the problem was in the video library compilation not linking to ogre since the g++ commands don't mention ogre, but the cmakelists.txt seems to be fine (I confirms that it finds ogre and that ogre is included in the target_link_libraries)
My second thought we're that perhaps they link to different versions of ogre but that can't be as they both find the same ogre installation and same ogre libraries.
Is anyone able to spot what I might be doing wrong and what I could try to fix the issue?
Thanks!
I managed to solve it.
Reordering the list of libraries to link in the target_link_libraries command such that the new video library was included before ogre seems to have solved my problem.
I'll accept my own answer in 6 hours
My friend made OpenGL graphic engine, but he is working on Windows. I want to compile project with it.
I installed all required libs with headers, but now problem is with linking (project in Code::Blocks). I found paths for /usr/lib/libSOIL.a and /usr/local/lib/libglfw3.a, but what about:
C:\Program Files (x86)\CodeBlocks\MinGW\lib\libopengl32.a
C:\Program Files (x86)\CodeBlocks\MinGW\lib\assimp_debug-dll_win32\assimp.lib
Also, what I must modify in project file to compile it? It requires: glfw3, glm, gl3w.h, assimp, SOIL (this is what I get from .hpp files). I installed all headers (downloaded sources and make && make install)...
I tried to compile it from terminal with g++, but I don't know switches for libraries.
Current situation:
$ g++ Camera.o Entity.o Frustum.o gl3w.o Light.o Material.o Mesh.o Model.o ModelPart.o Shader.o Texture.o Utilities.o ../main.o -o main -L/usr/local/lib/libglfw3.a -lX11 -lXext -lXt -lSM -lGLU -lglut -lSOIL
/usr/bin/ld: gl3w.o: undefined reference to symbol 'glXGetProcAddress'
/usr/bin/ld: note: 'glXGetProcAddress' is defined in DSO /usr/lib/nvidia-313-updates/libGL.so.1 so try adding it to the linker command line
/usr/lib/nvidia-313-updates/libGL.so.1: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
(i added too much libraries to command line, I know)
EDIT
Added -lGL and -ldl and some problems comes out. Now, I'll trying compile it with makefile...
libopengl32 -> libGL.a
assimp -> libassimp.a ?
You gotta provide the Makefile you're compiling it with.
I want to use libx264 in one of my projects on windows. I compiled x264 with cygwin including the shared and static library. Everythin works out fine, also the static and dynamic libraries are properly installed in cygwin.
When trying to compile another project that uses libx264 (gcc ... -lx264) I get an error:
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:406: undefined reference to `x264_param_default_preset(x264_param_t*, char const*, char const*)'
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:425: undefined reference to `x264_param_apply_profile(x264_param_t*, char const*)'
The linker seems to have problem with my built libraries of libx264, but what is exactly wrong here? How can I correctly link x264?
The full build output looks like this:
Build of configuration Debug for project test **
make all
Building target: test.exe
Invoking: Cygwin C++ Linker
g++ -L"/cygdrive/c/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib" -L"/cygdrive/c/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86" -L/usr/local/lib -o "test.exe" ./main.o -lx264.dll -lKernel32 -lUser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -ld3dx9d -ld3d9 -loleaut32 -luuid -lm
./main.o: In function `_Z8InitX264ii':
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:406: undefined reference to `x264_param_default_preset(x264_param_t*, char const*, char const*)'
/cygdrive/c/Users/Erik/workspace/test/Debug/../main.cpp:425: undefined reference to `x264_param_apply_profile(x264_param_t*, char const*)'
collect2: ld returned 1 exit status
make: *** [test.exe] Error 1
**** Build Finished ****
Thanks for your help!
You're using C++, not C. x264 is a C library, the names are probably getting mangled.
Try
extern "C" {
#include "x264.h"
}
--- old suggestions follow ---
Why are you linking aginst 'lx264.dll' anod not just 'lx264'?
Also, it looks like you're trying to link Microsoft .lib files in. Usually object files aren't binary-compatible between compilers/linkers... though it may be different on Cygwin. And according to your comment below, it is different... so nevermind.