Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > ObjC/C linking

ObjC/C linking
Thread Tools
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Santa Monica, CA
Status: Offline
Reply With Quote
Jan 6, 2001, 06:10 PM
 
I'm having trouble calling C functions from within ObjC code, getting "undefined symbol: _nameOfMyCFunction" errors.
Calling those same C functions from within C++ and linking pose no problem.

Obviously, I'm missing something rather fundamental. But what?

I'm using ProjectBuilder for this, no hand-made makefiles or custom link lines.
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 7, 2001, 02:34 PM
 
Let me guess... you put your functions in the same file as the main function, right? Well, don't do that! If that's what you did, then even if your prototyped your functions before the main you will still get that error. You see, the only thing in the main, by default if a call to NSApplication. That basically runs your program and the rest is done through your classes. Well, because objective C seems to be,f or the most part, dynamically linked, the main function has no knowledge of what's in your classes because that part is all pasted together at runtime via crap in the nib file. The cool thing about that is that you can very easily test a program before you have finished writing it. The downside is that you have to be creative in where you put your functions. So, the solution that I have found is to throw all of your functions and global variables into a header file that other things can include.

uhhh.. oh yea. I had forgotten. One problem that I have is that if multiple things use the headerfile that you define your functions an glabal variables in then it won't link because you get a Multiply Defined Symbols error. I don't know a way around that.

[This message has been edited by Dalgo (edited 01-07-2001).]
     
oliver  (op)
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Santa Monica, CA
Status: Offline
Reply With Quote
Jan 7, 2001, 09:28 PM
 
I do have my C function definition in a separate .c file and it's prototype in a .h file. Both have been added to the project. I tried putting them into both the "Classes" and "Other Sources" categories, with the same result.
Similarly, C functions in a shared library are not found by the linker.
Once again, everything is fine in C++, only ObjC and C doesn't work for me.
     
oliver  (op)
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Santa Monica, CA
Status: Offline
Reply With Quote
Jan 7, 2001, 10:38 PM
 
Update: "Clean" and rebuild fixed the problem. The function and file in question used to be C++. Apparently, PB continued to compile it as C++ even after I changed it to C. Similarly, my shared lib exports a function that looks like C (what the prototype is concerned) but is really C++.
That was actually the original motivation for what I tried: masquerading C++ to look like C so I can call it from ObjC. Lesson learnt: this is pointless. Fair enough.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2