I'm taking over a C++ project developed with Dev-C++ (yeah, I know...): it compiles fine but it won't link and the error message is not very indicative:
Compiler: Default compiler
Building Makefile: "S:\Spirale 2\spiral2\conditionnement\trunk2011\Makefile.win"
Finding dependencies for file: S:\Spirale 2\spiral2\conditionnement\trunk2011\spirale2.cpp
Finding dependencies for file: S:\Spirale 2\spiral2\conditionnement\trunk2011\sp_pulse.cpp
Finding dependencies for file: S:\Spirale 2\spiral2\conditionnement\trunk2011\sp_cb.cpp
Finding dependencies for file: S:\Spirale 2\spiral2\conditionnement\trunk2011\sp_daq.cpp
Finding dependencies for file: S:\Spirale 2\spiral2\conditionnement\trunk2011\sp_rs232.c
Executing make...
make.exe -f "S:\Spirale 2\spiral2\conditionnement\trunk2011\Makefile.win" all
g++.exe -D__DEBUG__ obj/spirale2.o obj/sp_pulse.o obj/sp_cb.o obj/sp_daq.o obj/sp_rs232.o obj/Spirale2_private.res -o "Spirale2.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/gtk+-bundle_2.22.1-20101227_win32/bin" -L"C:/RSSI/lib/msc" -L"C:/RSSI/lib/bc" -L"C:/Dev-Cpp/gtk+-bundle_2.22.1-20101227_win32/lib" -L"C:/Dev-Cpp/libiconv-1.9.1.bin.woe32/lib" -mwindows -lgtk-win32-2.0 -lgdk-win32-2.0 -lgthread-2.0 -lgdi32 -lole32 -luuid -latk-1.0 -lgdk_pixbuf-2.0 -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv -lrssism -g3
obj/spirale2.o: could not read symbols: Invalid argument
collect2: ld returned 1 exit status
make.exe: *** [Spirale2.exe] Error 1
Execution terminated
I broke down the last instruction to the linker here (one line per option for readability) and ran it from the command line:
c:/Dev-Cpp/libexec/gcc/mingw32/3.4.2/collect2.exe
--subsystem windows
-Bdynamic
-o Spirale2.exe
c:/Dev-Cpp/lib/crt2.o
c:/Dev-Cpp/lib/gcc/mingw32/3.4.2/crtbegin.o
-LC:/Dev-Cpp/lib
-LC:/Dev-Cpp/gtk+-bundle_2.22.1-20101227_win32/bin
-LC:/RSSI/lib/msc
-LC:/RSSI/lib/bc
-LC:/Dev-Cpp/gtk+-bundle_2.22.1-20101227_win32/lib
-LC:/Dev-Cpp/libiconv-1.9.1.bin.woe32/lib
-Lc:/Dev-Cpp/lib/gcc/mingw32/3.4.2
-Lc:/Dev-Cpp/lib/gcc
-Lc:/Dev-Cpp/mingw32/lib
-Lc:/Dev-Cpp/lib
obj/spirale2.o
obj/sp_pulse.o
obj/sp_cb.o
obj/sp_daq.o
obj/sp_rs232.o
obj/Spirale2_private.res
-lgtk-win32-2.0
-lgdk-win32-2.0
-lgthread-2.0
-lgdi32
-lole32
-luuid
-latk-1.0
-lgdk_pixbuf-2.0
-lpangowin32-1.0
-lgdi32
-lpango-1.0
-lgobject-2.0
-lgmodule-2.0
-lglib-2.0
-lintl
-liconv
-lrssism
-lstdc++
-lmingw32
-lgcc
-lmoldname
-lmingwex
-lmsvcrt
-lgdi32
-lcomdlg32
-luser32
-lkernel32
-ladvapi32
-lshell32
-lmingw32
-lgcc
-lmoldname
-lmingwex
-lmsvcrt
c:/Dev-Cpp/lib/gcc/mingw32/3.4.2/crtend.o
obj/spirale2.o: could not read symbols: Invalid argument
collect2: ld returned 1 exit status
I thought it might have been a file with the wrong CPU architecture, but I've checked the .o files:
crt2.o: 80386 COFF executable not stripped - version 30821
crtbegin.o: 80386 COFF executable not stripped - version 30821
crtend.o: 80386 COFF executable not stripped - version 30821
sp_cb.o: 80386 COFF executable not stripped - version 30821
sp_daq.o: 80386 COFF executable not stripped - version 30821
spirale2.o: 80386 COFF executable not stripped - version 30821
sp_pulse.o: 80386 COFF executable not stripped - version 30821
sp_rs232.o: 80386 COFF executable not stripped - version 30821
Any idea ? Thanks.
Like I said, the project is old and only needs a few modifications, so I don't really want to upgrade everything !
Related
This question seems to have been asked a zillion times, but unfortunately, none of the answers helped me.
I believe I have installed gtk correctly. My pkg-config environment seems okay. I'm not so sure of gcc.
I removed all the mingw and cygwin folders from my path environment, as I am only going to be using msys2 packages. So I have my path environment this way:-
GTK_LIB_DIR
C:\msys64\mingw64\lib
PKG_CONFIG_PATH
C:\msys64\mingw64\lib\pkgconfig
Path - C:\msys64\usr\bin;C:\msys64\mingw64\bin;%GTK_LIB_DIR%
The problem I am having is with compilation. Running this...
gcc pkg-config --cflags gtk+-3.0 -o gtkTest C:\dev\test_gtk3.c pkg-config --libs gtk+-3.0
I get...
cc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: `pkg-config: No such file or directory
gcc: error: gtk+-3.0`: No such file or directory
gcc: error: unrecognized command line option '--cflags'
gcc: error: unrecognized command line option '--libs'
I can run the following commands separately, with expected results. e.g.
pkg-config --cflags gtk+-3.0
pkg-config --libs gtk+-3.0
gcc -o gtkTest C:\dev\test_gtk3.c
Of course the last command returns an error, since gtk is not referenced.
I tried various combinations, some of my own. Some recommended, but one error persists, on pkg-config.
e.g.
C:\WINDOWS\system32>gcc -o gtkTest C:\dev\test_gtk3.c "pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0"
gcc: error: pkg-config --cflags gtk+-3.0 pkg-config --libs gtk+-3.0: No such file or directory
The last answer I found says "If pkg-config reports that it couldn't find the package, then you didn't install the Gtk development package as offered by your Linux distribution."
I'm using Windows, but I think I installed gtk correctly, since I followed the instructions, and I get what seems to be the expected results (please correct me if I am mistaken).
C:\WINDOWS\system32>pkg-config --cflags gtk+-3.0
-pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/m
ingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/fribidi -I/mingw6
4/include -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include
/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/
mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw
64/include/gdk-pixbuf-2.0 -I/mingw64/include -I/mingw64/lib/libffi-3.2.1/include
-I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include
C:\WINDOWS\system32>pkg-config --libs gtk+-3.0
-L/mingw64/lib -L/mingw64/lib/../lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32
-limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lep
oxy -lopengl32 -lgdi32 -lpangocairo-1.0 -lm -lgdi32 -lpangoft2-1.0 -lm -lpangowi
n32-1.0 -lm -lusp10 -lgdi32 -lpango-1.0 -lm -lfribidi -lthai -ldatrie -latk-1.0
-lcairo-gobject -lcairo -lz -lpixman-1 -lm -pthread -lfontconfig -liconv -lexpat
-lfreetype -lbz2 -lharfbuzz -lm -lusp10 -lgdi32 -lrpcrt4 -lgraphite2 -lpng16 -l
z -lgdk_pixbuf-2.0 -lm -lgio-2.0 -pthread -lintl -lshlwapi -ldnsapi -liphlpapi -
lws2_32 -lgmodule-2.0 -pthread -lintl -lz -lgobject-2.0 -pthread -lintl -lffi -l
glib-2.0 -lintl -lws2_32 -lole32 -lwinmm -lshlwapi -pthread -lm -lpcre
C:\WINDOWS\system32>gcc -o gtkTest C:\dev\test_gtk3.c | pkg-config --cflags --libs gtk+-3.0
-pthread -mms-bitfields -I/mingw64/include/gtk-3.0 -I/mingw64/include/cairo -I/m
ingw64/include -I/mingw64/include/pango-1.0 -I/mingw64/include/fribidi -I/mingw6
4/include -I/mingw64/include/atk-1.0 -I/mingw64/include/cairo -I/mingw64/include
/pixman-1 -I/mingw64/include -I/mingw64/include/freetype2 -I/mingw64/include -I/
mingw64/include/harfbuzz -I/mingw64/include -I/mingw64/include/libpng16 -I/mingw
64/include/gdk-pixbuf-2.0 -I/mingw64/include -I/mingw64/lib/libffi-3.2.1/include
-I/mingw64/include/glib-2.0 -I/mingw64/lib/glib-2.0/include -I/mingw64/include
-L/mingw64/lib -L/mingw64/lib/../lib -L/mingw64/lib -lgtk-3 -lgdk-3 -lz -lgdi32
-limm32 -lshell32 -lole32 -Wl,-luuid -lwinmm -ldwmapi -lsetupapi -lcfgmgr32 -lep
oxy -lopengl32 -lgdi32 -lpangocairo-1.0 -lm -lgdi32 -lpangoft2-1.0 -lm -lpangowi
n32-1.0 -lm -lusp10 -lgdi32 -lpango-1.0 -lm -lfribidi -lthai -ldatrie -latk-1.0
-lcairo-gobject -lcairo -lz -lpixman-1 -lm -pthread -lfontconfig -liconv -lexpat
-lfreetype -lbz2 -lharfbuzz -lm -lusp10 -lgdi32 -lrpcrt4 -lgraphite2 -lpng16 -l
z -lgdk_pixbuf-2.0 -lm -lgio-2.0 -pthread -lintl -lshlwapi -ldnsapi -liphlpapi -
lws2_32 -lgmodule-2.0 -pthread -lintl -lz -lgobject-2.0 -pthread -lintl -lffi -l
glib-2.0 -lintl -lws2_32 -lole32 -lwinmm -lshlwapi -pthread -lm -lpcre
C:\dev\test_gtk3.c:1:10: fatal error: gtk/gtk.h: No such file or directory
1 | #include <gtk/gtk.h>
| ^~~~~~~~~~~
compilation terminated.
Has anyone here struggled with this for hours, like I have, and finally got to understand what the problem is.
Please share your solution. Thank you.
Using this Installing gtk and compiling using gcc under windows? helped me get past the errors.
I used the following suggestion.
"Instead of a batch file, you may find more convenient to create an
user environmental variable and store the flags in there, that way you
will be able to compile from within a normal command prompt."
So I created two new environment variables (e.g. GTK_FLAGS_VARS; GTK_LIBS_VARS), and pasted the outputs in the variable values. Then in path place %GTK_FLAGS_VARS%;%GTK_LIBS_VARS%
Afterward gcc -o gtkTest C:\dev\test_gtk3.c %GTK_FLAGS_VARS% %GTK_LIBS_VARS%
I'm running 64 bit windows and 64 bit matlab. Following the instructions of an answer to a question on stackoverflow, I tried to configure a make file to compile my C function for use in matlab.
Here is the Makefile file:
MINGWPATH=/cygdrive/c/cygwin
CYGPATH=/cygdrive/c/cygwin
MATLABROOT=/cygdrive/c/Progra~1/MATLAB/R2011a
CC=i686-pc-mingw32-gcc
CFLAG= -Wall -m32 -O3 -Iinclude -I$(MATLABROOT)/extern/include $(SRC) $(LIBS) -o $(EXE)
MEXFLAG=-m64 -shared -DMATLAB_MEX_FILE -I$(MATLABROOT)/extern/include -Wl,--export-all-symbols $(LIBS) $(MEXSRC) -o $(MEXTGT).mexw64
LIBS= -Llib -L$(MATLABROOT)/bin/win64 -L$(MATLABROOT)/extern/lib/win64/microsoft -lmex -lmx -lmwlapack -lmwblas -leng
EXE= gopenfunction.exe
MEXTGT= gopenfunction.m
SRC= gopenfunction.c
MEXSRC = gopenfunction.c
all:$(EXE)
$(EXE): $(SRC)
$(CC) $(CFLAG) -ladvapi32 -luser32 -lgdi32 -lkernel32 -lmingwex -o $(EXE)
Output
$ make
i686-w64-mingw32-gcc -Wall -m32 -O3 -Iinclude -I/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include gopenfunction.c -Llib -L/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64 -L/cygdrive/c/Progra~1/MATLAB/R2011a/extern/lib/win64/microsoft -lmex -lmx -lmwlapack -lmwblas -leng -o gopenfunction.exe -ladvapi32 -luser32 -lgdi32 -lkernel32 -lmingwex -o gopenfunction.exe
/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64/libmex.dll: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
Makefile:18: recipe for target 'gopenfunction.exe' failed
make: *** [gopenfunction.exe] Error 1
I also tried:
i686-w64-mingw32-gcc -m32 -shared -Iinclude -I"/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include" -DMATLAB_MEX_FILE -o bla.mexw64 -Wl,--export-all-symbols *.c -L"/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64" -lmex -lmx -leng -lmat
I am using GCC because I cannot find VS2008 or 2010, only VS Community 2015 which doesn't work when I try to setup with mex via mex -setup
Note that I changed from -m64 to -m32 because otherwise I received the error below. I'm not entirely sure what it does.
$ i686-w64-mingw32-gcc -m64 -shared -Iinclude -I"/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include" -DMATLAB_MEX_FILE -o bla.mexw64 -Wl,--export-all-symbols *.c -L"/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64" -lmex -lmx -leng -lmat
gopenfunction.c:1:0: sorry, unimplemented: 64-bit mode not compiled in
#include "gclibo.h"
Visual Studio Follow-Up
After installing Microsoft Visual C++ the compiler option popped up but requires the SDK. Attempting to install the sdk results in an error 'visual studio 2010 must be installed.' I also installed .NET 4 and SDK for Windows 7 as per the supported compilers for MATLAB 2011 page.
>> mex -setup
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2011a/win64.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[1] Microsoft Visual C++ 2010 Express in C:\Program Files (x86)\Microsoft Visual Studio 10.0\
[0] None
Compiler: 1
Please verify your choices:
Compiler: Microsoft Visual C++ 2010 Express
Location: C:\Program Files (x86)\Microsoft Visual Studio 10.0\
Are these correct [y]/n? y
*****************************************************************************
Error: Microsoft Visual C++ 2010 Express requires the Microsoft Windows
Software Development Kit (SDK), but the SDK cannot be found.
For more information about the required SDK, see:
http://www.mathworks.com/support/compilers/R2011a/win64.html
*****************************************************************************
??? Error using ==> mex at 208
Unable to complete successfully.
Cygwin Follow-Up
I changed the compiler but now there is an undefined reference to 'WinMain.'
$ make
x86_64-w64-mingw32-gcc -Wall -m64 -O3 -Iinclude -I/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include gopenfunction.c -Llib -L/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64 -L/cygdrive/c/Progra~1/MATLAB/R2011a/extern/lib/win64/microsoft -lmex -lmx -lmwlapack -lmwblas -leng -o gopenfunction.exe -ladvapi32 -luser32 -lgdi32 -lkernel32 -lmingwex -o gopenfunction.exe
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
/usr/src/debug/mingw64-x86_64-runtime-4.0.2-1/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
Makefile:18: recipe for target 'gopenfunction.exe' failed
make: *** [gopenfunction.exe] Error 1
edit - using the second method, I was able to compile using the new x86_64 compiler.
x86_64-w64-mingw32-gcc -m64 -shared -Iinclude -I"/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include" -DMATLAB_MEX_FILE -o bla.mexw64 -Wl,--export-all-symbols *.c -L"/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64" -lmex -lmx -leng -lmat
edit2 - after investigating, the absence of -shared option is what causes the 'WinMain' error. I would really appreciate an explanation. I don't know anything about dlls, import libraries, shared libraries, etc, except that they are used at runtime. On the whole my problem has been solved and I thank everyone for their help.
$ x86_64-w64-mingw32-gcc -m64 -shared -Iinclude -I"/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include" -o bla.mexw64 *.c -L"/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64" -lmex -lmx -leng -lmat
$ x86_64-w64-mingw32-gcc -m64 -Iinclude -I"/cygdrive/c/Progra~1/MATLAB/R2011a/extern/include" -o bla.mexw64 *.c -L"/cygdrive/c/Progra~1/MATLAB/R2011a/bin/win64" -lmex -lmx -leng -lmat
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
/usr/src/debug/mingw64-x86_64-runtime-4.0.2-1/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
edit3 - looking at the original makefile in the question linked at the start, all of the above is already there under the $(MEXTGT) target. I just didn't understand how that would be called or used so I foolishly deleted it.
Despite having "w64" in the file name, i686-w64-mingw32-gcc.exe generates 32-bit binaries.
To generate 64-bit binaries, use x86_64-w64-mingw32-gcc.exe. In the cygwin package installer, look for mingw64-x86_64-.
"mingw64" GCC toolchains in the list below. The first targets 32-bit systems and the second 64-bit. They are named this way because they are from the "GCC for Win64" project (cygwin is not the only source for these toolchains). Also get the C toolchains (not shown below).
Also, based on my experience with the standalone mingw64, you probably need to add the following compiler flags to what you have:
-m64 -mwin32 -mdll ...
And you do need -shared as a linker flag.
I've installed the following two msi on my Windows 7 (basic) 64-bit — I downloaded the msi from here.
gstreamer-sdk-devel-x86_64-2013.6.msi
gstreamer-sdk-x86_64-2013.6.msi
Now I'm trying to build this hello world program using MinGW (GCC 4.8.1) and the linker is giving me trouble, saying this:
C:\Users\Apelles\AppData\Local\Temp\ccwLMXuu.o: In function `gst_message_unref':
C:/gstreamer-sdk/0.10/x86_64/include/gstreamer-0.10/gst/gstmessage.h:347: undefined reference to `gst_mini_object_unref'
C:\Users\Apelles\AppData\Local\Temp\ccwLMXuu.o: In function `main':
F:\projects\gstreamer/helloworld.c:9: undefined reference to `gst_init'
F:\projects\gstreamer/helloworld.c:12: undefined reference to `gst_parse_launch'
F:\projects\gstreamer/helloworld.c:15: undefined reference to `gst_element_set_state'
F:\projects\gstreamer/helloworld.c:18: undefined reference to `gst_element_get_bus'
F:\projects\gstreamer/helloworld.c:19: undefined reference to `gst_bus_timed_pop_filtered'
F:\projects\gstreamer/helloworld.c:24: undefined reference to `gst_object_unref'
F:\projects\gstreamer/helloworld.c:25: undefined reference to `gst_element_set_state'
F:\projects\gstreamer/helloworld.c:26: undefined reference to `gst_object_unref'
collect2.exe: error: ld returned 1 exit status
Which lib(s) am I missing?
Here are options which I used to build the project (taken from my make output):
gcc helloworld.c -ggdb -Wall -Wextra -ansi -std=c99 -Wno-unused-parameter -mms-bitfields -IC:/gstreamer-sdk/0.10/x86_64/include/gtk-2.0 -IC:/gstreamer-sdk/0.10/x86_64/lib/gtk-2.0/include -IC:/gstreamer-sdk/0.10/x86_64/include/atk-1.0 -IC:/gstreamer-sdk/0.10/x86_64/include/cairo -IC:/gstreamer-sdk/0.10/x86_64/include/gdk-pixbuf-2.0 -IC:/gstreamer-sdk/0.10/x86_64/include/pango-1.0 -IC:/gstreamer-sdk/0.10/x86_64/include/glib-2.0 -IC:/gstreamer-sdk/0.10/x86_64/lib/glib-2.0/include -IC:/gstreamer-sdk/0.10/x86_64/include/pixman-1 -IC:/gstreamer-sdk/0.10/x86_64/include/fontconfig -IC:/gstreamer-sdk/0.10/x86_64/include/freetype2 -IC:/gstreamer-sdk/0.10/x86_64/include -IC:/gstreamer-sdk/0.10/x86_64/include/libpng15 -mms-bitfields -IC:/gstreamer-sdk/0.10/x86_64/include/gstreamer-0.10 -IC:/gstreamer-sdk/0.10/x86_64/include/glib-2.0 -IC:/gstreamer-sdk/0.10/x86_64/lib/glib-2.0/include -IC:/gstreamer-sdk/0.10/x86_64/include/libxml2 -LC:/gstreamer-sdk/0.10/x86_64/lib -lgtk-win32-2.0 -lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -lintl -LC:/gstreamer-sdk/0.10/x86_64/lib -lgstinterfaces-0.10 -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lxml2 -lglib-2.0 -lintl
What is lacking in this?
What should I do in order to resolve this?
I suspect your are using MinGW's default GCC compiler which targets the x86 architecture but you have downloaded the x86_64 version of the SDK. The linker can find the libraries but I won't be able to use them.
We strongly recommend to use cerbero's build system to setup the development environment. It will take care of downloading a working toolchain and compile all the build dependencies (autotools, gettext, libtoo, pkg-config, etc...)
You will find detailed instructions here in the section Build a single project with the SDK
In short:
checkout cerbero's repo
run the bootstrap command with: ./cerbero-uninstalled -c config/win64.cbc bootstrap
enter the development shell with: ./cerbero-uninstalled -c config/win64.cbc shell
I'm compiled a GTK+ program using clang, rather than gcc. So far so good, except I can't have ld link correctly.
Original makefile called gcc to do the linking, like this:
gcc -g -O2 -export-dynamic -o my_application somefile.o another.o -pthread -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgconf-2 -lglade-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lxml2 -pthread -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lgthread-2.0 -lrt -lglib-2.0
If I simply substitute gcc with clang in the above command, I get this warning from the latter:
clang: warning: argument unused during compilation: '-e xport-dynamic'
Problem is: clang doesn't recognize "-export-dynamic" as a linker option, so it doesn't pass it off to ld. This causes the references to external functions to be scrapped: when final binary is executed, neither the menu options nor the buttons react.
If I do final linking step with gcc the binary works perfectly (even though it was really compiled with clang and gcc only does the linking). Since I'm trying to completely replace gcc with clang in my machine, this is not acceptable.
So I tried this:
ld /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtn.o -g -O2 -export-dynamic my_application somefile.o another.o -o -lgnomeui-2 -lSM -lICE -lbonoboui-2 -lgnomevfs-2 -lgnomecanvas-2 -lgnome-2 -lpopt -lbonobo-2 -lbonobo-activation -lORBit-2 -lart_lgpl_2 -lgconf-2 -lglade-2.0 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lxml2 -lgstreamer-0.10 -lgobject-2.0 -lgmodule-2.0 -lxml2 -lgthread-2.0 -lrt -lglib-2.0
By adding first 3 objects I avoid the "can't find _start" message. But then I get the aforementioned two complaints:
/usr/lib/crt1.o: In function _start:
(.text+0x12): undefined reference to __libc_csu_fini
/usr/lib/crt1.o: In function _start:
(.text+0x19): undefined reference to __libc_csu_init
I tried adding crtbegin.o and crtend.o at the list, even before crt1.o , to no avail. What is the linker's correct invocation?
(Post Edit): If nothing else works, is there a way to catch what exact parameters gcc is passing to ld when gcc is used for the linking?
gcc automatically adds language support libraries and objects to your supplied list for link. You have to add them yourself if you want to invoke ld directly. Taking an example from man ld, it could be
ld -o <output> /lib/crt0.o hello.o -lc
Try adding -lc, the symbol you need should be in it (at least on my system, it is).
You can use -Wl,-export-dynamic to pass -export-dynamic to ld without clang knowing about it.
I'm trying to compile a C program using GTK+ in bloodshed Dev-C++ 4.9.9.2.
I've added all the include files in the compiler options plus all compiler options, but I get the following error:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\Projects\Makefile.win" all
gcc.exe main.o -o "MyCProject.exe" -L"C:/Dev-Cpp/lib" -lgtk-win32-2.0 -lgdk-win32-2.0 -limm32 -lshell32 -lole32 -latk-1.0 -lgdk_pixbuf-2.0 -lcairo -lpangoft2-1.0 -lpangowin32-1.0 -lgdi32 -lpango-1.0 -lm -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -lfreetype -lzdll -lfontconfig -lpng13 -lpangocairo-1.0
C:\Dev-Cpp\Bin..\lib\gcc\mingw32\3.4.2........\mingw32\bin\ld.exe: cannot find -lintl
collect2: ld returned 1 exit status
make.exe: *** [MyCProject.exe] Error 1
Execution terminated
Can someone help me with what '-lintl' is and if it's a package missing or some file?
LibIntl
http://gnuwin32.sourceforge.net/packages/libintl.htm
You can get devpak from HERE
Aside:
I don't think Dev-C++ has been updated in years. Have you considered moving to Code::Blocks