XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static) Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
BenKissBox
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 30, 2020 2:22 pm
Location: France / Netherlands

XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by BenKissBox » Thu Jan 30, 2020 2:54 pm

Hello everybody,
I am trying to port a wxWidgets application on Mac OS. My configuration is :
  • MacOS X 10.13.6 (High Sierra)
  • wxWidgets 3.1.3
  • XCode 7
I have been able to compile the static library using wxcocoa.xcodeproj, which produced libwx_osx_cocoa_static.a (compiled as Debug and Release configurations) and I have been able to compile and run the minimal application, using minimal_cocoa.xcodeproj :D

I have created a test application following the tutorial here : https://wiki.wxwidgets.org/Creating_Xco ... plications

but XCode fails with an error : compilation is OK but linker stops with the following error "Library not found for -lwx_osx_cocoa_static".

I don't understand at all from where this linker error comes from. My project is linked to libwx_osx_cocoa_static.a (added to the project using the Link Binary with Libraries build phase) not to anything called wx_osx_cocoa_static

I tried to find the library the linker looks for in wxWidgets directory, but it does not seem to exist. The only files I find with this name are wx_osx_cocoa_static.LinkFileList and wx_osx_cocoa_static_.hmap, which are in the build directory.

I am pretty sure that I make a really stupid error, but since I am searching for the cause of this error since this morning, my eyes are getting blurry #-o

What is the thing I am missing (what should I do in my XCode project to solve this issue) ?

Thank you for your help....

Benoit

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4235
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by ONEEYEMAN » Thu Jan 30, 2020 4:19 pm

Hi,
The error you are seeing comes from the fact that you are not linking to the wx librar-ies.

I never compiled the library using the Xcode - only with Terminal. However I do compile my project with Xcode.

The file name you are seeing in the error is the same as libXXX.a. The *nix/Mac buuild system knows that the official library names start with "lib" prefix, and when its time to linking - it strips that prefix away.

Now in order to fix your problem - you said that you were able to successfully build the minimal sample from the Xcode project supplied. Open that Xcode project again and check where in the options does it say that it needs those files. Remember - the name for the library is not starting with "lib" - it is "wx_osx_cocoa_static".

Also, the fact that the error doesn't mention the extension of the library is worrisome. Just check the original minimal.xcodeproj and compare it with your own project option by option. You should see an error in yours.

Thank you.

BenKissBox
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 30, 2020 2:22 pm
Location: France / Netherlands

Re: XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by BenKissBox » Thu Jan 30, 2020 6:04 pm

ONEEYEMAN wrote:
Thu Jan 30, 2020 4:19 pm
Now in order to fix your problem - you said that you were able to successfully build the minimal sample from the Xcode project supplied. Open that Xcode project again and check where in the options does it say that it needs those files. Remember - the name for the library is not starting with "lib" - it is "wx_osx_cocoa_static".

Also, the fact that the error doesn't mention the extension of the library is worrisome. Just check the original minimal.xcodeproj and compare it with your own project option by option. You should see an error in yours.
Thank you.
Hi ONEEYEMAN,

thank you for your explanations. I was not aware that XCode was stripping the lib part in the filename...
I checked in the original project (minimal), and I found that it includes wxcocoa.xcodeproj directly in the project itself (so compiling minimal.xcodeproj re-generates the static library even if it is already existing)
So what I just tried in minimal project is to remove the embedded wxcocoa.xcodeproj and link libwx_osc_cocoa_static.a with the project by dragging it into "Link Binary With Libraries"
And try to guess what happens : I get now the same error in minimal project !! :?

I will try to recompile the library using command line, just in case (but I am pretty sure that XCode has generated correctly the .a file)
I remember there was a guide somewhere in the wiki, explaining how to compile the library for static use from command line, but I can not find it anymore.
If you know the URL for this guide, could you give it to me (or tell me the sequence I need to enter in terminal to compile it) ?

Thanks

Benoit

BenKissBox
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 30, 2020 2:22 pm
Location: France / Netherlands

Re: XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by BenKissBox » Thu Jan 30, 2020 6:19 pm

Hi ONEEYEMAN,

I think I have solved the issue... I tried something very basic : I moved the library from the /build directory directly into the project source directory.

Don't ask me why, but after that, I have been able to compile minimal.app without the linker error. No idea why, since the file location was appearing correctly (it was wx/build/osx/build/Debug/libwx_osx_cocoa_static.a. and now it is wx/samples/minimal/libwx_osx_cocoa_static.a)
Just moving the library file (and replacing the path in the project file of course) made XCode create the minimal app as expected (and this time, the embedded xcodeproj to generate the library is not even here...)

I will investigate on this, maybe it's a compiler issue (XCode 7 being quite old, I will try to generate the minimal project with XCode 9 and XCode 10 as I have both of them on my machine). Or maybe something related to the fact that I have 3 versions of XCode on the same machine... I already have seen strange things in the past because I had multiple versions of the same compiler installed.

But at least, this proves that the library generated by XCode IDE works as well as the one generated by command line, just in case you would want to try :lol:

I will post the results of my investigations here, it may help other wxWidgets users

Benoit

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4235
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by ONEEYEMAN » Thu Jan 30, 2020 7:41 pm

Hi,
BenKissBox wrote:
Thu Jan 30, 2020 6:04 pm
ONEEYEMAN wrote:
Thu Jan 30, 2020 4:19 pm
Now in order to fix your problem - you said that you were able to successfully build the minimal sample from the Xcode project supplied. Open that Xcode project again and check where in the options does it say that it needs those files. Remember - the name for the library is not starting with "lib" - it is "wx_osx_cocoa_static".

Also, the fact that the error doesn't mention the extension of the library is worrisome. Just check the original minimal.xcodeproj and compare it with your own project option by option. You should see an error in yours.
Thank you.
Hi ONEEYEMAN,

thank you for your explanations. I was not aware that XCode was stripping the lib part in the filename...
Its not an Xcode - it is an *nix build system.
If you run the "./wx-config --libs" from the build directory you will see what I mean.
BenKissBox wrote:
Thu Jan 30, 2020 6:04 pm
I checked in the original project (minimal), and I found that it includes wxcocoa.xcodeproj directly in the project itself (so compiling minimal.xcodeproj re-
generates the static library even if it is already existing)
Yes, you don't want to do that. ;-)
BenKissBox wrote:
Thu Jan 30, 2020 6:04 pm
So what I just tried in minimal project is to remove the embedded wxcocoa.xcodeproj and link libwx_osc_cocoa_static.a with the project by dragging it into "Link Binary With Libraries"
And try to guess what happens : I get now the same error in minimal project !! :?
Unfortunately I'm not at home right now.
But when I get there I will tell you what to put and where in order to fix the error you are seeing.
BenKissBox wrote:
Thu Jan 30, 2020 6:04 pm
I will try to recompile the library using command line, just in case (but I am pretty sure that XCode has generated correctly the .a file)
I remember there was a guide somewhere in the wiki, explaining how to compile the library for static use from command line, but I can not find it anymore.
If you know the URL for this guide, could you give it to me (or tell me the sequence I need to enter in terminal to compile it) ?
Its easy and straightforward:

Code: Select all

cd wxWidgets
mkdir buildMac
cd buildMac
../configure --enable-debug --disable-shared
make
Just don't do "--disable-shared" and it will produce dynamic libraries.

Thank you.

BenKissBox
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 30, 2020 2:22 pm
Location: France / Netherlands

Re: XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by BenKissBox » Fri Jan 31, 2020 1:23 pm

Hi ONEEYEMAN,

thank you for explanations about command line compilation.

Meanwhile, I have performed some tests and I confirm the root cause of the issue : if I drag/drop the .a file from the osx/build/ directory, XCode does not see the library and fails during link edition (however I can see the correct path in the properties pane. No idea why the linker can't find it :?: )

If I copy the library in the project directory and drag/drop it in XCode, everything works fine, Xcode compiles and link the application without any problem.

Just to be sure, I will repeat the test with more recent versions of XCode, maybe there was a bug in XCode 7, but at least problem is solved now

Benoit

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4235
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: XCode linker error (wx_osx_cocoa_static / libwx_osx_cocoa_static)

Post by ONEEYEMAN » Fri Jan 31, 2020 3:27 pm

Hi,
If you open that option in the propject do you see just:

Code: Select all

-lwx_osx_cocoa_static.a
?

Because this is definitely wrong.

If you try to do this:

Code: Select all

cd wxWidgets/buildMac && ./wx-config --libs
in the output you will find the option:

Code: Select all

-L<path_to_wx>/wxWidgets/buildMac
The "-L" option sets the search path for the linker where it looks for the libraries to link.

Now, out of curiosity - did you build a monolithic static version of the library?
While (still) supported, building monolithic wxWidgets library is discouraged. And also building static version of the library on*nix-based system is also discouraged. Because it will basically link into your application the whole Cocoa library/SDK. I'm not sure about Apple licensing, but you may be in violation.

There is no gain in building the monolithic library and you might experience problems doing so with your own applicationwx_osx_cocoa_static.a.

The best way to build is:

Code: Select all

cd wxWidgets && mkdir buildMac && cd buildMac && ../configure --enable-debug -- enable-shared --with-macosx-version-min=10.9 && make
Thank you.

Post Reply