LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2003, 03:04 PM   #1
Joe-E
LQ Newbie
 
Registered: Apr 2003
Posts: 4

Rep: Reputation: 0
g++ static build problem


I am trying to build a program statically. I compiled all of the source files similar to the following:

g++ -static -I/usr/include/gtkmm-2.0 -I/usr/lib/gtkmm-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/sigc++-1.2/include -I/usr/include/sigc++-1.2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/atk-1.0 -c CharFil.cc

Then I linked everything as follows:

c++ -static -g -O2 -I/usr/include/gtkmm-2.0 -I/usr/lib/gtkmm-2.0/include -I/usr/include/gtk-2.0 -I/usr/lib/sigc++-1.2/include -I/usr/include/sigc++-1.2 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/freetype2 -I/usr/include/atk-1.0 -o CharFil CharFil.o OutNameDlg.o OverwriteDlg.o WarningDlg.o DoneDlg.o SplashDlg.o AboutDlg.o HelpDlg.o InputFileSelection.o CFilter.o AsciiDlg.o dirbrowser.o -Wl,--export-dynamic /usr/lib/libgtkmm-2.0.so /usr/lib/libgdkmm-2.0.so /usr/lib/libatkmm-1.0.so /usr/lib/libgtk-x11-2.0.so /usr/lib/libpangomm-1.0.so /usr/lib/libglibmm-2.0.so /usr/lib/libsigc-1.2.so /usr/lib/libgdk-x11-2.0.so /usr/lib/libatk-1.0.so /usr/lib/libgdk_pixbuf-2.0.so -lm /usr/lib/libpangoxft-1.0.so /usr/lib/libpangox-1.0.so /usr/lib/libpango-1.0.so /usr/lib/libgobject-2.0.so /usr/lib/libgmodule-2.0.so -ldl /usr/lib/libglib-2.0.so

Everything compiled and linked without errors. The executable CharFil was created, but when I try to run CharFil I receive the following message:

./CharFil: No such file or directory

I have tried to build the project statically several other ways, without success. The above was my first attempt.

Any help would be appreciated,

Joe-E
 
Old 04-12-2003, 07:07 PM   #2
stamour547
LQ Newbie
 
Registered: Apr 2003
Location: NY, USA
Posts: 16

Rep: Reputation: 0
i know im pretty new to linux so if anything i say is wrong someone please correct me, but i think you have to change the file permission on CharFil so that you have execute permission. If you dont have permission i think that is the error message you will get.

stamour547
 
Old 04-14-2003, 08:10 AM   #3
Joe-E
LQ Newbie
 
Registered: Apr 2003
Posts: 4

Original Poster
Rep: Reputation: 0
I checked the permissions and the binary was already execuatble. So unfortunatly that doesn't seem to be the problem, but thank you for your advice stamour547.


Here's another attempt I made at statically linking:

c++ -o CharFil CharFil.o OutNameDlg.o OverwriteDlg.o WarningDlg.o DoneDlg.o SplashDlg.o AboutDlg.o HelpDlg.o InputFileSelection.o CFilter.o AsciiDlg.o dirbrowser.o -L/usr/X11R6/lib -Wl,-Bstatic -lgtkmm-2.0 -lgdkmm-2.0 -latkmm-1.0 -lgtk-x11-2.0 -lpangomm-1.0 -lglibmm-2.0 -lsigc-1.2 -latk-1.0 -lm -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lpangox-1.0 -lpangoxft-1.0 -lgdk_pixbuf-2.0 -lgdk-x11-2.0

Which throws the following errors:

/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgtk-x11-2.0.a(gtkplug.o)(.text+0x10c2): In function `send_xembed_message':
: undefined reference to `XSendEvent'
/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgtk-x11-2.0.a(gtkplug.o)(.text+0x121e): In function `xembed_set_info':
: undefined reference to `XChangeProperty'
/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgtk-x11-2.0.a(gtksocket.o)(.text+0x4ff): In function `gtk_socket_realize':
: undefined reference to `XGetWindowAttributes'
/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgtk-x11-2.0.a(gtksocket.o)(.text+0x52a): In function `gtk_socket_realize':
: undefined reference to `XSelectInput'

.......etc............etc..............etc.................etc............etc...............

/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgdk-x11-2.0.a(gdkinput-xfree.o)(.text+0x1a5): In function `gdk_input_check_proximity':
: undefined reference to `XFreeDeviceState'
/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgdk-x11-2.0.a(gdkinput-xfree.o)(.text+0x539): In function `_gdk_input_grab_pointer':
: undefined reference to `XGrabDevice'
/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgdk-x11-2.0.a(gdkinput-xfree.o)(.text+0x585): In function `_gdk_input_grab_pointer':
: undefined reference to `XUngrabDevice'
/usr/lib/gcc-lib/i386-linux/3.2.3/../../../libgdk-x11-2.0.a(gdkinput-xfree.o)(.text+0x613): In function `_gdk_input_ungrab_pointer':
: undefined reference to `XUngrabDevice'
collect2: ld returned 1 exit status

If I link the following libraries dynamically, everything works fine: -lgdk_pixbuf-2.0 and -lgdk-x11-2.0. But this is not a static binary:

CharFil: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped

It has the following dependancies:

libgdk_pixbuf-2.0.so.0 => /usr/lib/libgdk_pixbuf-2.0.so.0 (0x4001f000)
libgdk-x11-2.0.so.0 => /usr/lib/libgdk-x11-2.0.so.0 (0x40031000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40094000)
libm.so.6 => /lib/libm.so.6 (0x4013d000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x4015e000)
libc.so.6 => /lib/libc.so.6 (0x40166000)
libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40276000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
libgmodule-2.0.so.0 => /usr/lib/libgmodule-2.0.so.0 (0x40332000)
libdl.so.2 => /lib/libdl.so.2 (0x40336000)
libgobject-2.0.so.0 => /usr/lib/libgobject-2.0.so.0 (0x40339000)
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0 (0x40368000)
libXi.so.6 => /usr/X11R6/lib/libXi.so.6 (0x403ca000)
libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x403d2000)
libXft.so.2 => /usr/X11R6/lib/libXft.so.2 (0x403e0000)
libz.so.1 => /lib/libz.so.1 (0x403f0000)
libXrender.so.1 => /usr/X11R6/lib/libXrender.so.1 (0x403fd000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x40402000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x40426000)
libpangoxft-1.0.so.0 => /usr/lib/libpangoxft-1.0.so.0 (0x40475000)
libpangox-1.0.so.0 => /usr/lib/libpangox-1.0.so.0 (0x40494000)
libpango-1.0.so.0 => /usr/lib/libpango-1.0.so.0 (0x404a0000)
libexpat.so.1 => /usr/lib/libexpat.so.1 (0x404cf000)

Are my static libraries different from their shared library equivalents?

Thank you in advance for any help anyone can give me,

Joe-E
 
Old 04-14-2003, 03:17 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I might be on the completely wrong track here,
but I believe that you were using the dynamic
libraries in your first example, too :}

The names of the static libraries all end in .a,
not .so.


Cheers,
Tink
 
Old 04-15-2003, 12:25 PM   #5
Joe-E
LQ Newbie
 
Registered: Apr 2003
Posts: 4

Original Poster
Rep: Reputation: 0
Yes, I was hoping the -static flag used in the first example would link the shared libraries and their dependancies statically (if that can be done). What confused me was that I recieved no errors while compiling or linking. The binary executable was created, but when I attempted to run it the binary executable was not found.

In the second example the -static flag is used again, and the required libraries are included without the explicit instructions on whether to use their shared or static elements. I think in this case the -static flag instructs the linker to use all of the corresponding .a library files. However when I do this I recieve a large number of undefined reference errors. It's almost as if the .a library files do not include everything their .so equivalents do.

Hope someone can help,

Joe-E
 
Old 04-15-2003, 02:37 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I'm really starting to guess here,
I've never dieved into static linkage
with a TON of interdependent packages...

Maybe you'll have to recompile
gdk_pixbuf-2.0 and gdk-x11-2.0 for
static linkage, too?

Cheers,
TInk
 
Old 04-16-2003, 07:38 AM   #7
Joe-E
LQ Newbie
 
Registered: Apr 2003
Posts: 4

Original Poster
Rep: Reputation: 0
That's my problem. When I try to link gdk_pixbuf-2.0 and gdk-x11-2.0 statically I receive all of those errors. I'm beginning to wonder if it's even possible, but I am hopeful it is and someone out there has done it and can help me.

Joe-E
 
Old 10-21-2004, 01:05 AM   #8
mundri
LQ Newbie
 
Registered: Apr 2004
Posts: 8

Rep: Reputation: 0
Static compilation

The library included in ur stitic compilation program may be interdependent so try to change there position and then try ..... u can find out .la file of the same library on which libs this lib depends .... hope this will solve ur problem..
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto Assign Multiple Static Public IP Addresses under SBC's PPPoE Static Ip system o trekgraham Linux - Networking 8 04-17-2007 10:51 AM
FC2 Overriding static if in favor of dhcp system set for static pkraus109 Linux - Networking 8 09-21-2004 11:13 AM
How can I use gcc to build a static library? vtluu Red Hat 1 04-12-2004 10:45 AM
I can't build static programs Red Guy Programming 3 01-19-2003 01:43 AM
Glibc 2.3.1 build causes segfaults with static bash mdh Linux From Scratch 2 11-12-2002 06:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration