 |
 |
ObjC/C linking
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Santa Monica, CA
Status:
Offline
|
|
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
|
|
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).]
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Santa Monica, CA
Status:
Offline
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jan 2001
Location: Santa Monica, CA
Status:
Offline
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|