PDA

View Full Version : Linking issues with XCode + FPC for iPhone



Relfos
03-03-2011, 11:07 AM
Hi!
I'm trying to port my game engine to run on iPhone, so I used the FPC OpenGL template as startup point.
Now in PascalLibrary.pas it says 'Add all your Pascal units to 'uses' clause..."
My game engine contains about 70 different units, do I need to add them all there?

I can compile with no problem the empty template (with the spinning fpc logo)
Is it necessary to have -mmacpas mode defined?
I removed this in the settings and it still compiles and runs ok. I ask this because my engine was originally written in Delphi/Windows, and later ported to FPC and uses mode Delphi switches everywhere.

Now the other problem, just adding for example my unit TERRA_Utils to PascalLibrary causes lots of linking errors

_FINALIZES_TERRA_GL, referenced from.
INITFINAL in PascalLibrary.o
_FINALIZES_TERRA_OS, referenced from
INITFINAL in PascalLibrary.o
_FINALIZES_TERRA_LOG, referenced from
INITFINAL in PascalLibrary.o
_THREADVARLIST_TERRA_APPLICATION, referenced from
FPC_THREADVARTALES in PascalLibrary.o

and lots of similar errors.
I already have the -Wl, -no_order_inits in the project settings, what could be the problem?
(I'm using FPC 2.5.1)

JSoftware
03-03-2011, 11:59 AM
Have you tried rebuilding everything?

Relfos
03-03-2011, 12:14 PM
I was almost sure that I already did try that, but I just did a clean + build and the errors did change, this time errors in the actual units (functions that need to be ported) and not linking errors.
Well, time to work, I will ask again here in case I have more problems

Relfos
03-03-2011, 01:09 PM
I'm back, after fixing all compilation errors in the units, now I've done a clean, and the linking problem is there again, saying that cannot find the initialization and finalizations of the included units in the generated pascallibrary.o
What could be the problem?

JSoftware
03-03-2011, 02:15 PM
A broken linker? Try to inspect the object files manually and use -Sh to view the linker script

Relfos
03-03-2011, 02:34 PM
I've disable dead code stripping and still the same result.
I've added -Sh to the "other linker flags" but I don't much difference.
However I tried to look at hedgewars xcode project settings, copied some stuff and now reduce from 24 linking errors to 10.
How to inspect the object files manually?

Relfos
03-03-2011, 02:41 PM
I'm trying to figure this linking process.
Well, we have the pascallibrary.pas that is the main file and has all the other units in the uses clauses (TERRA_Utils, TERRA_Application, etc)

Now, it I understood correctly, the objective is to build a library called libfpc.a, that will contain all the stuff.
The linker is trying to look at pascallibrary.o for those missing symbols (_FINALIZES_TERRA_UTILS, etc)
But I suppose those are actually in their respective .o files, like TERRA_Utils.o?
If is that, then I need to add them to the step where the library is assembled from the various .o files I guess, I'm kind of a noob at this kind of things :(

Relfos
03-03-2011, 03:16 PM
Ok, I finally found the problem, I needed to add all source files for the units in the uses clause to the XCode project.
Only 5 linker errors remaining.
The only problem now, is two of the needed files appear greyed out in the Add Files dialog and I don't have an idea why :s

EDIT: Fixed, I dropped the files directly from Finder, it seems to be a bug in XCode or something..

Ingemar
30-05-2011, 04:58 AM
Many of your problems sound familiar. Are you using OpenGLES? If so, how? Any ObjC code in your project?

Relfos
30-05-2011, 10:11 AM
Many of your problems sound familiar. Are you using OpenGLES? If so, how? Any ObjC code in your project?

Yes, using OpenGL ES and some bits of objC, however the problem is already fixed, thanks!

Ingemar
30-05-2011, 01:02 PM
Yes, using OpenGL ES and some bits of objC, however the problem is already fixed, thanks!

That's good, I just wanted to see if you had any all-FPC solution. I have written an all-FPC OpenGLES test program, which misbehaves for no reason I can find. It works in the iPad simulator, but not for iPhone. That could, of course, be the topic of a new thread, but this was close enough to ask IMHO.

Relfos
30-05-2011, 01:03 PM
Ah, I see. I still don't know how to make everything using only fpc though.

Stoney
30-05-2011, 02:29 PM
Using FPC only can be achieved by using SDL 1.3 (Pascal headers are here: https://github.com/Stoney-FD/sdl13-pascal), worked so far for FPC 2.4.2 and FPC 2.5.1 for me, to be honest it's still a bit quirky at the moment, as the SDL 1.3 documentation is pretty much non-existant and much of the API changed since I did my tutorial on SDL 1.3 and iOS last year.

Ingemar
31-05-2011, 08:06 AM
Using FPC only can be achieved by using SDL 1.3 (Pascal headers are here: https://github.com/Stoney-FD/sdl13-pascal), worked so far for FPC 2.4.2 and FPC 2.5.1 for me, to be honest it's still a bit quirky at the moment, as the SDL 1.3 documentation is pretty much non-existant and much of the API changed since I did my tutorial on SDL 1.3 and iOS last year.

IMHO that only packages the foreign code. (You can say that about Cocoa too but it isn't quite the same.) The ObjC code includes something important: framebuffer objects. I want to access that from my FPC code, not only for setting up my main frame buffer but for multipass rendering.

I have ported the glext unit (which was missing in the interfaces) but I probably have some remaining bugs that prevent it from working. But that is the way to go as I see it. We will all package it in various ways, in our game libraries, but we need the direct access to glext too.

Andru
31-05-2011, 08:15 AM
Using FPC only can be achieved by using SDL 1.3
And ZenGL ;) Everything works for me, and currently I'm working on porting two commercial projects to iOS.