ld failing to find wxWidgets - c++

I'm trying to make the minimal sample for wxWidgets. I'm getting the following output:
$ mingw32-make -f makefile.gcc
g++ -c -o gcc_mswud\minimal_minimal.o -g -O0 -mthreads -DHAVE_W32API_H -D__WXMS
W__ -D_UNICODE -I.\..\..\lib\gcc_lib\mswud -I.\..\..\include -W -Wall -I
. -I.\..\..\samples -DNOPCH -Wno-ctor-dtor-privacy -MTgcc_mswud\minimal_min
imal.o -MFgcc_mswud\minimal_minimal.o.d -MD -MP minimal.cpp
g++ -o gcc_mswud\minimal.exe gcc_mswud\minimal_sample_rc.o gcc_mswud\minimal_min
imal.o -g -mthreads -L.\..\..\lib\gcc_lib -Wl,--subsystem,windows -mwindows
-lwxmsw29ud_core -lwxbase29ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxreg
exud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -ls
hell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lwini
net
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxmsw29ud_core
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxbase29ud
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxtiffd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxjpegd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxpngd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxzlibd
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxregexud
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot fin
d -lwxexpatd
collect2.exe: error: ld returned 1 exit status
makefile.gcc:222: recipe for target 'gcc_mswud\minimal.exe' failed
mingw32-make: *** [gcc_mswud\minimal.exe] Error 1
For some reason I cannot find the wxwidgets libraries; I think I may have set some environment variable up incorrectly or perhaps I should have moved them to /mingw/lib?
Could someone help me track this down or point me in the right direction, I'd really appreciate it.
Thanks!

You have told gcc to link the wxWidget libraries but haven't told it where to find them.
Just add -Lc:/your_wxwidget_path to the command line options for for the linker and it should link.

Did you build wxWidgets libraries as explained in the MinGW section of the documentation? It looks like the linker can't find the libraries because they are simply not there -- which would seem to indicate that you didn't build them. You need to do this first, before building the samples.

Related

Making WxWidgets work in C++

I installed precompiled WxWidget libraries and tried to run the default program in CodeBlocks but it gives the following error:
mingw32-g++.exe: error: bin\Release\new2.exe: No such file or directory
Paths for WxWidget Libraries and MinGW are already specified.
My question is; How to make CodeBlocks generate a .exe file for WxWidgets project?
I have already tried all solutions listed in this question: "No such file or directory" error in CodeBlocks
Complete Build Log:
-------------- Build: Release in new2 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -Wno-unused-
local-typedefs -Wall -O2 -ID:\WxWidgets\wxWidgets2.8\include -I\msw -c
C:\Users\ShifaShah\Documents\new2\new2App.cpp -o obj\Release\new2App.o
mingw32-g++.exe -pipe -mthreads -D__GNUWIN32__ -D__WXMSW__ -Wno-unused-
local-typedefs -Wall -O2 -ID:\WxWidgets\wxWidgets2.8\include -I\msw -c
C:\Users\ShifaShah\Documents\new2\new2Main.cpp -o obj\Release\new2Main.o
windres.exe -ID:\WxWidgets\wxWidgets2.8\include -I\msw -J rc -O coff -i
C:\Users\SHIFAS~1\DOCUME~1\new2\resource.rc -o obj\Release\resource.res
mingw32-g++.exe -L -o bin\Release\new2.exe obj\Release\new2App.o
obj\Release\new2Main.o obj\Release\resource.res -s -mthreads -lwxmsw_core -lwxbase -lwxpng -lwxzlib -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -
ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lcomctl32 -lwsock32 -lodbc32 -mwindows
mingw32-g++.exe: error: bin\Release\new2.exe: No such file or directory
Process terminated with status 1 (0 minute(s), 3 second(s))
1 error(s), 0 warning(s) (0 minute(s), 3 second(s))
-L -o bin\Release\new2.exe
Here's the problem. The -L flag requires an argument, but the usual argument (a directory to search for libraries) is not provided. So the next flag, -o, is interpreted as an argument to -L, and bin\Release\new2.exe is interpreted as a name of an input file, which of course doesn't exist yet.
Check your compiler flags and make sure there's no stray -L anywhere, and no "additional libraries directory" is specified as a white space string or similar.

Build clang on windows with cmake, WinMain reference undefined

i'm trying to build clang with mingw-w64 on windows (10), so i followed this tutorial : https://here-be-braces.com/blog/llvm-clang-on-windows-mingw-revisited
but cmake don't recognise gcc as an C++11 compiler. I run cmake with this command :
cmake C:\llvm -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_TOOLS=ON -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_BUILD_TESTS=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CXX_FLAGS="-IC:/mingw64/x86_64-w64-mingw32/include" -DGCC_INSTALL_PREFIX=%syspath% -DCMAKE_INSTALL_PREFIX=%syspath% -DCMAKE_EXE_LINKER_FLAGS="-lmingw32 -static-libgcc -static-libstdc++ -static -lstdc++ -lm -lpthread -lgcc -lmsvcrt -lmoldname -lgcc_eh -lkernel32 -luser32 -ladvapi32 -liconv -lmingwex" -DBUILD_SHARED_LIBS=OFF -DLLVM_PARALLEL_COMPILE_JOBS=2 -DLLVM_PARALLEL_LINK_JOBS=2 -DCMAKE_INCLUDE_PATH="C:/mingw64/x86_64-w64-mingw32/include" -DGCC_INSTALL_PREFIX="C:/mingw64" -DCMAKE_LIBRARY_PATH="C:/mingw64/x86_64-w64-mingw32/lib"
I obtened the list of librairies with "gcc -v test.c -Wl,--verbose", test.c is just an classic hello world. But with the libmingw32, I get this error :
cmd.exe /C "cd . && C:\mingw64\bin\gcc.exe -lmingw32 -static-libgcc
-static-libstdc++ -static -lstdc++ -lm -lpthread -lgcc -lmsvcrt -lmoldname
-lgcc_eh -lkernel32 -luser32 -ladvapi32 -liconv -lmingwex
CMakeFiles/cmTC_3b639.dir/testCCompiler.c.obj -o cmTC_3b639.exe
-Wl,--out-implib,libcmTC_3b639.dll.a
-Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32
-lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32
-ladvapi32 && cd ."
CMakeFiles/cmTC_3b639.dir/testCCompiler.c.obj:testCCompiler.c:(.text+0x0):
multiple definition of `main'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x0):
first defined here
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../x86_64-w64-mingw32/lib/../lib\libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e):
undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Without it, i get further, but i get this : http://pastebin.com/zeMViHzA
CMake Error at projects/libcxx/CMakeLists.txt:423 (message):
C++11 or greater is required but the compiler does not support c++11
How can i get rid of the "WinMain undefined reference" for the cmake tests ?
edit : the gcc version : 6.2.0

Cross compiling linker error

I am cross compiling a small c++ script for Windows on Linux.
It's made with Qt and uses curl, I compiled qt and curl via mxe (make qt5 and make curl).
I then run these commands:
$MXE/usr/i686-w64-mingw32.static/qt5/bin/qmake
make
Which gives me these errors:
release/main.o:main.cpp:(.text.startup+0x4b7): undefined reference to `_imp__curl_easy_init'
release/main.o:main.cpp:(.text.startup+0x6a8): undefined reference to `_imp__curl_easy_setopt'
release/main.o:main.cpp:(.text.startup+0x781): undefined reference to `_imp__curl_easy_perform'
release/main.o:main.cpp:(.text.startup+0x874): undefined reference to `_imp__curl_easy_cleanup'
When I compile it for Linux, there are no errors.
Here is my .pro file:
QT += core
QT -= gui
QT += network
CONFIG += c++11
TARGET = add_feeds
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -lcurl
Any help appreciated.
If you need any other info, feel free to ask.
EDIT:
Output of make VERBOSE=1
make -f Makefile.Release
make[1]: Entering directory `/root/compile/add_feeds'
i686-w64-mingw32.static-g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=gnu++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I../mxe/usr/i686-w64-mingw32.static/qt5/include -I../mxe/usr/i686-w64-mingw32.static/qt5/include/QtNetwork -I../mxe/usr/i686-w64-mingw32.static/qt5/include/QtCore -Irelease -I../mxe/usr/i686-w64-mingw32.static/qt5/mkspecs/win32-g++ -o release/main.o main.cpp
i686-w64-mingw32.static-g++ -c -pipe -fno-keep-inline-dllexport -O2 -std=gnu++0x -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_NETWORK_LIB -DQT_CORE_LIB -I. -I../mxe/usr/i686-w64-mingw32.static/qt5/include -I../mxe/usr/i686-w64-mingw32.static/qt5/include/QtNetwork -I../mxe/usr/i686-w64-mingw32.static/qt5/include/QtCore -Irelease -I../mxe/usr/i686-w64-mingw32.static/qt5/mkspecs/win32-g++ -o release/add_feeds_plugin_import.o add_feeds_plugin_import.cpp
i686-w64-mingw32.static-g++ -Wl,-s -Wl,-subsystem,console -mthreads -o release/add_feeds.exe release/main.o release/add_feeds_plugin_import.o -lcurl -L/root/compile/mxe/usr/i686-w64-mingw32.static/qt5/lib -L/root/compile/mxe/usr/i686-w64-mingw32.static/qt5/plugins/bearer /root/compile/mxe/usr/i686-w64-mingw32.static/qt5/plugins/bearer/libqgenericbearer.a /root/compile/mxe/usr/i686-w64-mingw32.static/qt5/plugins/bearer/libqnativewifibearer.a /root/compile/mxe/usr/i686-w64-mingw32.static/qt5/lib/libQt5Network.a -ldnsapi -liphlpapi -lssl -lcrypto -lgdi32 -lcrypt32 /root/compile/mxe/usr/i686-w64-mingw32.static/qt5/lib/libQt5Core.a -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32 -lmpr -lz -lpcre16
release/main.o:main.cpp:(.text.startup+0x4b7): undefined reference to `_imp__curl_easy_init'
release/main.o:main.cpp:(.text.startup+0x6a8): undefined reference to `_imp__curl_easy_setopt'
release/main.o:main.cpp:(.text.startup+0x781): undefined reference to `_imp__curl_easy_perform'
release/main.o:main.cpp:(.text.startup+0x874): undefined reference to `_imp__curl_easy_cleanup'
collect2: error: ld returned 1 exit status
make[1]: *** [release/add_feeds.exe] Error 1
make[1]: Leaving directory `/root/compile/add_feeds'
make: *** [release] Error 2
This problem comes from QT, when static compiling it.
Which QT Version do you have?QT Static compile bug report with Qt 5.13.0
I filed this bug report which had similar call to requqested functions.

Linker fail: member in archive is not an object

I'm trying to build Open CASCADE (6.7.1) library with 64bit mingw on Windows 7 (I am using x86_64-4.9.1-release-posix-seh-rt_v3-rev1 from mingw-w64 project).
When it comes to linking, it fails with an error and I have no idea what could be wrong. The linker command generated by cmake is:
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E remove -f CMakeFiles\TKernel.dir/objects.a
C:\msys64\mingw64\bin\ar.exe cr CMakeFiles\TKernel.dir/objects.a #CMakeFiles\TKernel.dir\objects1.rsp
C:\msys64\mingw64\bin\g++.exe -shared -o ..\out\bin\libTKernel.dll -Wl,--out-implib,..\out\lib\libTKernel.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -Wl,--whole-archive CMakeFiles\TKernel.dir/objects.a -Wl,--no-whole-archive -LC:\msys64\home\user\tcl8.5.16\build -LC:\msys64\home\user\freetype-2.5.3 -ladvapi32 -lgdi32 -luser32 -lkernel32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
And the produced error:
Linking CXX shared library ..\out\bin\libTKernel.dll
CMakeFiles\TKernel.dir/objects.a: member CMakeFiles\TKernel.dir/objects.a(FSD_BinaryFile.cxx.obj) in archive is not an object
collect2.exe: error: ld returned 1 exit status
TKernel\CMakeFiles\TKernel.dir\build.make:11422: recipe for target 'out/bin/libTKernel.dll' failed
This is how the files are compiled:
Building CXX object TKernel/CMakeFiles/TKernel.dir/__/__/src/FSD/FSD_BinaryFile.cxx.obj
cd /d TKernel && C:\msys64\mingw64\bin\g++.exe -DCSFDB -DTKernel_EXPORTS -DWNT -D_OCC64 -D_SCL_SECURE_NO_WARNINGS -MP -Wall -O3 -DNDEBUG -DNo_Exception #CMakeFiles/TKernel.dir/includes_CXX.rsp -MM -D__FSD_DLL -D__MMgt_DLL -D__OSD_DLL -D__Plugin_DLL -D__Quantity_DLL -D__Resource_DLL -D__SortTools_DLL -D__Standard_DLL -D__StdFail_DLL -D__Storage_DLL -D__TColStd_DLL -D__TCollection_DLL -D__TShort_DLL -D__Units_DLL -D__UnitsAPI_DLL -D__IncludeLibrary_DLL -D__Dico_DLL -D__NCollection_DLL -D__Message_DLL -o CMakeFiles\TKernel.dir\__\__\src\FSD\FSD_BinaryFile.cxx.obj -c ..\..\src\FSD\FSD_BinaryFile.cxx
If I check the objects.a file with nm, the contents are .obj, but "File format not recognized" doesn't look good... but don't know what exactly does that mean...
$ nm objects.a
C:\msys64\mingw64\x86_64-w64-mingw32\bin\nm.exe: FSD_BinaryFile.cxx.obj: File format not recognized
C:\msys64\mingw64\x86_64-w64-mingw32\bin\nm.exe: FSD_CmpFile.cxx.obj: File format not recognized
...
Output from file command:
$ file objects.a
objects.a: current ar archive
$ file __/__/src/FSD/FSD_BinaryFile.cxx.obj
__/__/src/FSD/FSD_BinaryFile.cxx.obj: ASCII text, with CRLF line terminators
I also tried to remove the --whole-archive option from the linker command, but that leads to another error:
Linking CXX shared library ..\out\bin\libTKernel.dll
CMakeFiles\TKernel.dir/objects.a: error adding symbols: Archive has no index; run ranlib to add one
collect2.exe: error: ld returned 1 exit status
If I run ranlib on the file, it doesn't help.
Any ideas are appreciated.
edit: Ok, so I guess that the problem is caused by -MM flag, that was used for the build. So it didn't really compile the files, if I understand it correctly.
However I found OCE project, which is some sort of community edition of OCC and it is quite mingw-ready, so I'm gonna use that version and see how it goes...

Why cant g++ find getnameinfo in ws2_32?

I dont understand why g++ cannot find getnameinfo in ws2_32, nm shows that it is there. Here is the output:
$ I:/Programs/MinGW/msys/1.0/bin/sh.exe ../libtool --tag=CXX --mode=link g++
-g -O2 -no-undefined -version-info 16:0:0 -o libetpan.la -rpath /i/Programs/M
inGW/lib dummy.lo versioninfo.lo data-types/libdata-types.la low-level/liblow-l
evel.la driver/libdriver.la main/libmain.la engine/libengine.la windows/libarch
.la -L/i/Programs/MinGW/lib -lws2_32 -liconv
libtool: link: rm -fr .libs/libetpan.dll.a
libtool: link: g++ -shared -nostdlib i:/programs/mingw/bin/../lib/gcc/mingw32/4.
7.0/../../../dllcrt2.o i:/programs/mingw/bin/../lib/gcc/mingw32/4.7.0/crtbegin.o
.libs/dummy.o .libs/versioninfo.o -Wl,--whole-archive data-types/.libs/libdat
a-types.a low-level/.libs/liblow-level.a driver/.libs/libdriver.a main/.libs/lib
main.a engine/.libs/libengine.a windows/.libs/libarch.a -Wl,--no-whole-archive
-lws2_32 -lws2_32 -lws2_32 -lws2_32 -lws2_32 -lws2_32 -L/i/Programs/MinGW/lib -l
ws2_32 /mingw/lib/libiconv.dll.a -Li:/programs/mingw/bin/../lib/gcc/mingw32/4.7.
0 -Li:/programs/mingw/bin/../lib/gcc -Li:/programs/mingw/bin/../lib/gcc/mingw32/
4.7.0/../../../../mingw32/lib -Li:/programs/mingw/bin/../lib/gcc/mingw32/4.7.0/.
./../.. -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi3
2 -lshell32 -luser32 -lws2_32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmi
ngwex -lmsvcrt i:/programs/mingw/bin/../lib/gcc/mingw32/4.7.0/crtend.o -O2 -p
thread -o .libs/libetpan-16.dll -Wl,--enable-auto-image-base -Xlinker --out-impl
ib -Xlinker .libs/libetpan.dll.a
Creating library file: .libs/libetpan.dll.a
Warning: resolving _closesocket by linking to _closesocket#4
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
low-level/.libs/liblow-level.a(mailsmtp.o): In function `get_hostname':
c:\libetpan-00c7589\src\low-level\smtp/mailsmtp.c:266: undefined reference to `_
getnameinfo'
collect2.exe: error: ld returned 1 exit status
$ nm /i/Programs/MinGW/lib/libws2_32.a | grep getnameinfo
00000000 I __imp__getnameinfo#28
00000000 T _getnameinfo#28
I needed to #define _WIN32_WINNT 0x0501