Re: C language in obj-c
On 29 Apr 2009, at 11:04, fawad shafi wrote: may be this question is odd, but i wana use .obj file created in c language, in objective-c. is it possible?? It depends what you mean. If you're asking if it's possible to use C code in a program that uses ObjC, of course. Usually you'd include the C source code in your project and Xcode will just compile it for you when you hit Build. Then you use the usual mechanisms to make use of your C code from your ObjC files (i.e. the extern keyword, function prototypes, header files and so on). You can, of course, include C code in ObjC files directly, since ObjC is just a superset of the underlying C language. If you are asking whether you can use .obj files built by (for instance) Microsoft's compiler, the answer is no. Microsoft's .obj files use an extended form of COFF, whereas the .o files generated by OS X compilers use Mach-O, and while it's theoretically possible that you could convert a COFF file to Mach-O and feed it through the OS X linker, the platforms have different ABIs (calling conventions, structure layout conventions and the like) and so most likely it would just break. If you're asking whether it's possible to include an object file in a project in a general sense, again the answer is yes. You might need to feed the linker some additional arguments though, to make it link against the extra object. However, as I say, the object file needs to be a Mach-O object and not (for instance) a Microsoft .obj file. Kind regards, Alastair. p.s. This type of question is better addressed to xcode-dev. -- http://alastairs-place.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: C language in obj-c
On 29 Apr 2009, at 11:25, Alastair Houghton wrote: Kind regards, Alastair. p.s. This type of question is better addressed to xcode-dev. Of course I meant xcode-users :-D Kind regards, Alastair. -- http://alastairs-place.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: C language in obj-c
Le 29 avr. 09 à 12:04, fawad shafi a écrit : Dear All, may be this question is odd, but i wana use .obj file created in c language, in objective-c. is it possible?? thanks in advance. Obj-C is a superset of C and can access any C code just like you can from any other C file. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: C language in obj-c
On 29 Apr 2009, at 11:29, fawad shafi wrote: for example i write one program in c language and then compile it, the compiler will create the one .obj file for us. if i wana use that obj file in xcode or obj-c, is it possible?? The system compiler on Mac OS X doesn't make files with the extension .obj, even for plain C code. That's why I suspected you might be talking about some other compiler (my guess being Microsoft's, since that's the most common place where you might see a .obj extension). Anyway, the easiest thing to do is to put your C source files into your Xcode project and it will compile them and link them against the rest of your program. Then you don't need to bother about the object files at all. Kind regards, Alastair. p.s. Please always reply to the list as well as directly. -- http://alastairs-place.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
RE: C language in obj-c
thanks for this useful info. is it possible? existing code that (possibly written in C) that we can easily port over to obj-c with minimum effort. Regards, Fawad Shafi CC: cocoa-dev@lists.apple.com From: alast...@alastairs-place.net To: fawadpaki_...@hotmail.com Subject: Re: C language in obj-c Date: Wed, 29 Apr 2009 11:33:54 +0100 On 29 Apr 2009, at 11:29, fawad shafi wrote: for example i write one program in c language and then compile it, the compiler will create the one .obj file for us. if i wana use that obj file in xcode or obj-c, is it possible?? The system compiler on Mac OS X doesn't make files with the extension .obj, even for plain C code. That's why I suspected you might be talking about some other compiler (my guess being Microsoft's, since that's the most common place where you might see a .obj extension). Anyway, the easiest thing to do is to put your C source files into your Xcode project and it will compile them and link them against the rest of your program. Then you don't need to bother about the object files at all. Kind regards, Alastair. p.s. Please always reply to the list as well as directly. -- http://alastairs-place.net _ Rediscover Hotmail®: Now available on your iPhone or BlackBerry http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Mobile2_042009___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: C language in obj-c
On 29 Apr 2009, at 11:35, Jean-Daniel Dupas wrote: Le 29 avr. 09 à 12:25, Alastair Houghton a écrit : Just for the record, with gcc-llvm, you can no longer assume that .o files are Mach-O object files. When you use Link-Time-Optimization (or -O4) with llvm-gcc (or clang), it produces llvm bytecode (even if the output extension remain .o) That's a good point. They still aren't COFF though, and you can still link Mach-O objects with the LLVM bitcode. Also, I haven't looked but it wouldn't surprise me to find that the .o files still had a Mach-O wrapper around the bitcode itself. Kind regards, Alastair. -- http://alastairs-place.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: C language in obj-c
Le 29 avr. 09 à 12:25, Alastair Houghton a écrit : On 29 Apr 2009, at 11:04, fawad shafi wrote: may be this question is odd, but i wana use .obj file created in c language, in objective-c. is it possible?? It depends what you mean. If you're asking if it's possible to use C code in a program that uses ObjC, of course. Usually you'd include the C source code in your project and Xcode will just compile it for you when you hit Build. Then you use the usual mechanisms to make use of your C code from your ObjC files (i.e. the extern keyword, function prototypes, header files and so on). You can, of course, include C code in ObjC files directly, since ObjC is just a superset of the underlying C language. If you are asking whether you can use .obj files built by (for instance) Microsoft's compiler, the answer is no. Microsoft's .obj files use an extended form of COFF, whereas the .o files generated by OS X compilers use Mach-O Just for the record, with gcc-llvm, you can no longer assume that .o files are Mach-O object files. When you use Link-Time-Optimization (or -O4) with llvm-gcc (or clang), it produces llvm bytecode (even if the output extension remain .o) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: C language in obj-c
Le 29 avr. 09 à 12:39, Alastair Houghton a écrit : On 29 Apr 2009, at 11:35, Jean-Daniel Dupas wrote: Le 29 avr. 09 à 12:25, Alastair Houghton a écrit : Just for the record, with gcc-llvm, you can no longer assume that .o files are Mach-O object files. When you use Link-Time-Optimization (or -O4) with llvm-gcc (or clang), it produces llvm bytecode (even if the output extension remain .o) That's a good point. They still aren't COFF though, and you can still link Mach-O objects with the LLVM bitcode. Also, I haven't looked but it wouldn't surprise me to find that the .o files still had a Mach-O wrapper around the bitcode itself. In fact, they don't. To handle these files, 'ld' try to load libLTO.dylib which works with llvm bytecode files directly. You can even manipulate them using llvm tools (you can use llvm-dis on such .o file to get the corresponding llvm assembly for example). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
RE: C language in obj-c
That depends upon the nature of the existing code... Quoting fawad shafi fawadpaki_...@hotmail.com: thanks for this useful info. is it possible? existing code that (possibly written in C) that we can easily port over to obj-c with minimum effort. Regards, Fawad Shafi CC: cocoa-dev@lists.apple.com From: alast...@alastairs-place.net To: fawadpaki_...@hotmail.com Subject: Re: C language in obj-c Date: Wed, 29 Apr 2009 11:33:54 +0100 On 29 Apr 2009, at 11:29, fawad shafi wrote: for example i write one program in c language and then compile it, the compiler will create the one .obj file for us. if i wana use that obj file in xcode or obj-c, is it possible?? The system compiler on Mac OS X doesn't make files with the extension .obj, even for plain C code. That's why I suspected you might be talking about some other compiler (my guess being Microsoft's, since that's the most common place where you might see a .obj extension). Anyway, the easiest thing to do is to put your C source files into your Xcode project and it will compile them and link them against the rest of your program. Then you don't need to bother about the object files at all. Kind regards, Alastair. p.s. Please always reply to the list as well as directly. -- http://alastairs-place.net _ Rediscover Hotmail®: Now available on your iPhone or BlackBerry http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Mobile2_042009___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/jmunson%40his.com This email sent to jmun...@his.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[OT] Re: C language in obj-c
On 29 Apr 2009, at 11:36, fawad shafi wrote: thanks for this useful info. is it possible? existing code that (possibly written in C) that we can easily port over to obj-c with minimum effort. You don't need to port C code to ObjC. ObjC is just C with some simple extensions. Similarly, ObjC++ is just C++ with the same simple extensions. The only problems you might have are things like non-portable assumptions in your code (e.g. structure layouts, byte ordering if you're targeting PPC machines as well as Intel, inline assembler) or places where your code isn't properly standards compliant. Exactly how much trouble you have depends on how portable the original code was. Just include the source files in your Xcode project, then hit Build. If you have errors at that point, you'll need to fix them. You'll also need to test quite carefully if this code is coming from another platform. Kind regards, Alastair. -- http://alastairs-place.net ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com