Problem statically linking libraries on OS X

CodeLite installation/troubleshooting forum
jimboh
CodeLite Curious
Posts: 8
Joined: Mon Jun 06, 2011 3:20 am
Genuine User: Yes
IDE Question: C++
Contact:

Problem statically linking libraries on OS X

Post by jimboh »

I have freetype2 and ftgl on my system through MacPorts. I assume that MacPorts compiled them for the architecture of my computer, an Intel-based iMac running OS X 10.6.7.

These are the Linker settings for the CodeLite project:

Append to global settings

Options: -mwindows;$(shell $(WX_TOOL) --debug=yes --libs --unicode=yes);-m32

Library Paths: /opt/local/lib

Libraries: libfreetype.a;libftgl.a;libz.a

All three libraries are in the /opt/local/lib directory.

When I try to build, I get the following errors:

ld: warning: ignoring file /opt/local/lib/libfreetype.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
ld: warning: ignoring file /opt/local/lib/libftgl.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
Undefined symbols for architecture i386:
"wxGLContext::SetCurrent()", referenced from:
gGraphWindow::OnPaint(wxPaintEvent&) in graphs_graph.o
"wxGLCanvas::SwapBuffers()", referenced from:
gGraphWindow::OnPaint(wxPaintEvent&) in graphs_graph.o
"wxGLCanvas::~wxGLCanvas()", referenced from:
gGraphWindow::~gGraphWindow()in graphs_graph.o
gGraphWindow::~gGraphWindow()in graphs_graph.o
gGraphWindow::~gGraphWindow()in graphs_graph.o
gGraphWindow::gGraphWindow()in graphs_graph.o
gGraphWindow::gGraphWindow()in graphs_graph.o
gGraphWindow::gGraphWindow(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long)in graphs_graph.o
gGraphWindow::gGraphWindow(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long)in graphs_graph.o
...
"wxGLCanvas::wxGLCanvas(wxWindow*, wxGLContext const*, int, wxPoint const&, wxSize const&, long, wxString const&, int*, wxPalette const&)", referenced from:
gGraphWindow::gGraphWindow()in graphs_graph.o
gGraphWindow::gGraphWindow()in graphs_graph.o
gGraphWindow::gGraphWindow(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long)in graphs_graph.o
gGraphWindow::gGraphWindow(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long)in graphs_graph.o
"FTPixmapFont::FTPixmapFont(char const*)", referenced from:
GraphInit() in graphs_graph.o
"FTTextureFont::FTTextureFont(char const*)", referenced from:
GraphInit() in graphs_graph.o
"wxGLContext::wxGLContext(__AGLPixelFormatRec*, wxGLCanvas*, wxPalette const&, wxGLContext const*)", referenced from:
gGraphWindow::gGraphWindow(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long)in graphs_graph.o
gGraphWindow::gGraphWindow(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long)in graphs_graph.o
"wxGLCanvas::Show(bool)", referenced from:
vtable for gGraphWindowin graphs_graph.o
"wxGLCanvas::MacSuperChangedPosition()", referenced from:
vtable for gGraphWindowin graphs_graph.o
"wxGLCanvas::MacTopLevelWindowChangedPosition()", referenced from:
vtable for gGraphWindowin graphs_graph.o
"wxGLCanvas::MacVisibilityChanged()", referenced from:
vtable for gGraphWindowin graphs_graph.o
"typeinfo for wxGLCanvas", referenced from:
typeinfo for gGraphWindowin graphs_graph.o
"wxGLCanvas::ms_classInfo", referenced from:
__static_initialization_and_destruction_0(int, int)in graphs_graph.o
"_iconv", referenced from:
wxMBConv_iconv::GetMBNulLen() const in libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::WC2MB(char*, wchar_t const*, unsigned long) constin libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::MB2WC(wchar_t*, char const*, unsigned long) constin libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(wchar_t const*)in libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(wchar_t const*)in libwx_base_carbonud-2.8.a(baselib_strconv.o)
(maybe you meant: wxMBConv_iconv::~wxMBConv_iconv(), wxMBConv_iconv::~wxMBConv_iconv(), wxMBConv_iconv::~wxMBConv_iconv(), vtable for wxMBConv_iconv, wxMBConv_iconv::wxMBConv_iconv(wchar_t const*), wxMBConv_iconv::wxMBConv_iconv(wchar_t const*), typeinfo name for wxMBConv_iconv, typeinfo for wxMBConv_iconv, wxMBConv_iconv::Clone() const , wxMBConv_iconv::GetMBNulLen() const , wxMBConv_iconv::ms_wcNeedsSwap , wxMBConv_iconv::IsOk() const , wxMBConv_iconv::ms_wcCharsetName , wxMBConv_iconv::MB2WC(wchar_t*, char const*, unsigned long) const, wxMBConv_iconv::WC2MB(char*, wchar_t const*, unsigned long) const, new_wxMBConv_iconv(wchar_t const*))
"_iconv_close", referenced from:
wxMBConv_iconv::~wxMBConv_iconv()in libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::~wxMBConv_iconv()in libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::~wxMBConv_iconv()in libwx_base_carbonud-2.8.a(baselib_strconv.o)
"_iconv_open", referenced from:
wxMBConv_iconv::wxMBConv_iconv(wchar_t const*)in libwx_base_carbonud-2.8.a(baselib_strconv.o)
wxMBConv_iconv::wxMBConv_iconv(wchar_t const*)in libwx_base_carbonud-2.8.a(baselib_strconv.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make[1]: *** [Debug/SleepyHead.app/Contents/MacOS/SleepyHead] Error 1
make[1]: Leaving directory `/Users/Jimbo/sleepyhead/Projects/CodeLite/OSX'
make: *** [All] Error 2
make: Leaving directory `/Users/Jimbo/sleepyhead/Projects/CodeLite/OSX'
----------Build Ended----------
0 errors, 6 warnings, total time: 00:00:12 seconds

Odd that the messages say "0 errors" after so many problems.

Odd that the first two "ld:" warnings refer to .dylib files when I specified .a files.

The architecture references are odd, since MacPorts presumably built for my system.

What am I doing wrong? How do I fix it? This is driving me nuts! :cry:
jimboh
CodeLite Curious
Posts: 8
Joined: Mon Jun 06, 2011 3:20 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by jimboh »

To be perfectly clear, this is a screenshot of the Linker page of my Project Settings:
2011-06-12_1327.png
You do not have the required permissions to view the files attached to this post.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by eranif »

Not really codelite related.. but more of wx issue

Some advises:
- Make sure that the wx library you are using is built with wxGL support (OpenGL)
- Try asking your questions in a more wxWidgets oriented forum like: http://wxforum.shadonet.com/

Eran
Make sure you have read the HOW TO POST thread
jimboh
CodeLite Curious
Posts: 8
Joined: Mon Jun 06, 2011 3:20 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by jimboh »

eranif wrote:Not really codelite related
I will follow your advice, but I must ask why I am getting messages about .dylib files being ignored when I specified .a files in CodeLight? That seems very odd.
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by eranif »

ld: warning: ignoring file /opt/local/lib/libfreetype.dylib, file was built for unsupported file format which is not the architecture being linked (i386)
I think that this says it all

Eran
Make sure you have read the HOW TO POST thread
jimboh
CodeLite Curious
Posts: 8
Joined: Mon Jun 06, 2011 3:20 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by jimboh »

but why was the .dylib file passed to gcc when I told CodeLight to use the .a file?
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by eranif »

jimboh wrote:but why was the .dylib file passed to gcc when I told CodeLight to use the .a file?
As usual, when asking build problems - the *complete* log should be included (use code tags)

If you would have provided the full log you would have seen the link line that was created by codelite :

Code: Select all

..... -lfreetype .....
Since you are under Mac, I would say that the link has a priority for .dylib over .a (FYI: .so also has priority over .a)
So if the link finds 2 libraries in its path, one with .a and one with .dylib -> it will pick the .dylib one.

If you want to link explicitly against a librarym you should put it in the 'Options' field of the 'Linker' page like this:
if I am reading your Options correct, the line should like similar to:

Code: Select all

-mwindows;$(shell $(WX_TOOL) --debug=yes --unicode=yes)'-m32;/opt/local/lib/libfreetype.a

Eran
Make sure you have read the HOW TO POST thread
Auria
CodeLite Enthusiast
Posts: 26
Joined: Sat Oct 30, 2010 7:19 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by Auria »

On OSX 10.6.x, GCC builds 64-bits by default. So likely all your macports libraries are 64-bits
jimboh
CodeLite Curious
Posts: 8
Joined: Mon Jun 06, 2011 3:20 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by jimboh »

Thank you, both.

It turns out the problem was conflicting installations of wxwidgets, with part of each in the path and part of each not in the path. MacPorts did this. I had to remove and reinstall both from scratch.
jimboh
CodeLite Curious
Posts: 8
Joined: Mon Jun 06, 2011 3:20 am
Genuine User: Yes
IDE Question: C++
Contact:

Re: Problem statically linking libraries on OS X

Post by jimboh »

eranif wrote:a more wxWidgets oriented forum like: http://wxforum.shadonet.com/
BTW, did that forum move? I haven't been able to access it for several days.
Post Reply