Linker fail: member in archive is not an object - c++

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...

Related

Error decomposing gcc command into separate compile and link steps

I am getting a linker error building a simple project using scons. The example commands show integrated compiling and linking of program binaries, which scons does not do (though I probably could force it to, I'd rather not if possible).
This command works fine:
gcc -o main.exe main.cpp C:\raylib\raylib\src\raylib.rc.data -s -static -Os -IC:\raylib\raylib\src -DPLATFORM_DESKTOP -lraylib -lopengl32 -lgdi32 -lwinmm
Whereas these two fail:
g++ -o main.o -c -DPLATFORM_DESKTOP -Os -static -IC:\raylib\raylib\src main.cpp
ld -o mains.exe c:\raylib\raylib\src\raylib.rc.data -s -static main.o -LC:\raylib\raylib\src -lraylib -lopengl32 -lgdi32 -lwinmm
Resulting in:
c:\raylib\w64devkit\bin\ld: cannot find -lopengl32
c:\raylib\w64devkit\bin\ld: cannot find -lgdi32
c:\raylib\w64devkit\bin\ld: cannot find -lwinmm
Any insights? I'm not particularly familiar with the .rc.data files.
I would try to get gcc's library search path:
]$ gcc -x cpp-output -E -v /dev/null 2>&1 | grep LIBRARY_PATH | sed 's/:/\n/g'
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/11/
/usr/lib/gcc/x86_64-linux-gnu/11/../../../x86_64-linux-gnu/
/usr/lib/gcc/x86_64-linux-gnu/11/../../../../lib/
/lib/x86_64-linux-gnu/
/lib/../lib/
/usr/lib/x86_64-linux-gnu/
/usr/lib/../lib/
/usr/lib/gcc/x86_64-linux-gnu/11/../../../
/lib/
/usr/lib/
see if the missing libraries are in any of those directories, and if they are then add them to the ld invocation as -L<path> option.
EDIT
To see ld search path when it is called on its own, I think this should work:
]$ ld --verbose | grep SEARCH_DIR | sed 's/;/\n/g'
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu")
SEARCH_DIR("=/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu64")
SEARCH_DIR("=/usr/local/lib64")
SEARCH_DIR("=/lib64")
SEARCH_DIR("=/usr/lib64")
SEARCH_DIR("=/usr/local/lib")
SEARCH_DIR("=/lib")
SEARCH_DIR("=/usr/lib")
SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64")
SEARCH_DIR("=/usr/x86_64-linux-gnu/lib")
When you eliminate duplicates you'll notice that /usr/lib/gcc/x86_64-linux-gnu/11/ is an additional directory that is being searched when linking with gcc (your first command) but not when linking directly with ld.
But that's on my machine. On yours it will probably be a bit different.

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.

Library linking using wxWidgets through Cygwin

I have been trying to get wxWidgets working on Cygwin. So far I have had success by using a mingw compiler available through the cygwin installer.
The build seemed to work fine. The configure message I used was:
configure --host=i686-w64-mingw32 --build=i686-pc-cygwin --enable-static --disable-shared
After that I ran a make and make install and got no errors.
Next I grabbed an example from a tutorial and ran:
i686-w64-mingw32-g++ -c -o hello_world.o hello_world.cpp CXX_FLAGS
i686-w64-mingw32-g++ -o a hello_world.o CXX_FLAGS LIBS
where CXX_FLAGS and LIBS are generated from wx-config -cxxflags and wx-config --libs. This works fine, but when I try to run the executable I get this error:
C:/Users/sam/Documents/cpp/wxwidgets_tutorial/a.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
The libraries I build should be static, so I'm not sure what to do with this message. Any help is greatly appreciated!
Some more info:
wx-config --cxxflags gives the output:
-I/usr/local/lib/wx/include/i686-w64-mingw32-msw-unicode-static-3.0 -I/usr/local/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -D__WXMSW__ -mthreads
wx-config --libs give the output:
-L/usr/local/lib -Wl,--subsystem,windows -mwindows /usr/local/lib/libwx_mswu_xrc-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_webview-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_qa-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_baseu_net-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_html-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_adv-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_mswu_core-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_baseu_xml-3.0-i686-w64-mingw32.a /usr/local/lib/libwx_baseu-3.0-i686-w64-mingw32.a -lpng -ljpeg -ltiff -lexpat -lwxregexu-3.0-i686-w64-mingw32 -lz -lrpcrt4 -loleaut32 -lole32 -luuid -lwinspool -lwinmm -lshell32 -lcomctl32 -lcomdlg32 -ladvapi32 -lwsock32 -lgdi32
ls /usr/local/lib:
libwx_baseu_net-3.0-i686-w64-mingw32.a
libwx_baseu_xml-3.0-i686-w64-mingw32.a
libwx_baseu-3.0-i686-w64-mingw32.a
libwx_mswu_adv-3.0-i686-w64-mingw32.a
libwx_mswu_aui-3.0-i686-w64-mingw32.a
libwx_mswu_core-3.0-i686-w64-mingw32.a
libwx_mswu_gl-3.0-i686-w64-mingw32.a
libwx_mswu_html-3.0-i686-w64-mingw32.a
libwx_mswu_media-3.0-i686-w64-mingw32.a
libwx_mswu_propgrid-3.0-i686-w64-mingw32.a
libwx_mswu_qa-3.0-i686-w64-mingw32.a
libwx_mswu_ribbon-3.0-i686-w64-mingw32.a
libwx_mswu_richtext-3.0-i686-w64-mingw32.a
libwx_mswu_stc-3.0-i686-w64-mingw32.a
libwx_mswu_webview-3.0-i686-w64-mingw32.a
libwx_mswu_xrc-3.0-i686-w64-mingw32.a
libwxregexu-3.0-i686-w64-mingw32.a
libwxscintilla-3.0-i686-w64-mingw32.a
wx
EDIT:
Following VZ's advise, I added /usr/i686-w64-mingw32/sys-root/mingw/bin to my path... It compiles!
However when run, the program does not open any window, just exits immediately. Is this still a library problem?
You need to copy the required DLLs (at least libstdc++-6.dll and libgcc_s_sjlj-1.dll) from /usr/i686-w64-mingw32/sys-root/mingw/bin to a directory in your PATH or the application directory (or add this directory itself to your PATH, of course).
You can use cygcheck or (native) dependency walker tool to find which DLL is actually missing.

Why do I get this error when I compile a C++ program in jgrasp?

----jGRASP exec: gcc -g -o C1.exe C1.c -lglu32 -lfreeglut -lopengl32`
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../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 am using mingw32 compiler and I followed the instructions from the link below:
http://users.csc.calpoly.edu/~akeen/courses/csc101/references/gcc.html
Hope that someone knows what to do
thank you
You probably need to specify the location of the freeglut library with the flag -L /path/to/freeglut, so compile as
gcc -g -o C1.exe C1.c -L/path/to/freeglut -lglu32 -lfreeglut -lopengl32
or, if you use an IDE, there should be an option to specify the location of the libraries used by the linker.
See http://users.csc.calpoly.edu/~phatalsk/references/jGrasp_gcc_Setup/GCC_JGrasp_Install.html
Settings/Compiler Settings/Workspace, add the flag to C/L field.

ld failing to find wxWidgets

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.