Compiling a .c file as an Objective-C file - success!

1 view
Skip to first unread message

AlBlue

unread,
Feb 17, 2009, 10:45:02 PM2/17/09
to ObjectivEClipse Development Group
With a code snippet:

main()
{
NSLog(@"Hello World')
}

and using the standard 'C' template, I was able to get it to execute
if I passed -x objective-c to the compiler and -framework Foundation
to the linker arguments. The -framework is an Apple extension but -x
objective-c is a standard one. I think for GNUStep code, -lobjc would
be needed but I'm not sure what else.

If I rename it to .m, it doesn't get picked up as a source file to be
compiled (unsurprisingly) but at least it shows CDT can be used to
compile an Objective-C program with suitable massaging of the
parameters.

I'm thinking that the project should probably define what frameworks
are to be linked or have it on a per-target basis, which will then
affect what the linker will do.

Alex

Mario

unread,
Feb 18, 2009, 6:55:40 AM2/18/09
to ObjectivEClipse Development Group
hello Alex,

I can acknowlegde the parameters works.

here my Code:

int main(int argc, char *argv[]) {
NSLog(@"Hello World");
return 0;
}

here are my verbose compile console messages:
**** Build of configuration Debug for project testC1 ****

make all
Building file: ../src/testC1.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -x objective-c -v -MMD -MP -
MF"src/testC1.d" -MT"src/testC1.d" -o"src/testC1.o" "../src/testC1.c"
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5490~1/src/configure --disable-
checking -enable-werror --prefix=/usr --mandir=/share/man --enable-
languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/
$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/
lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --
host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5490)
/usr/libexec/gcc/i686-apple-darwin9/4.0.1/cc1obj -quiet -v -MMD
testC1.dsrc/testC1.o -MFsrc/testC1.d -MP -MTsrc/testC1.d -MQ src/
testC1.o -dD -D__DYNAMIC__ ../src/testC1.c -fPIC -quiet -dumpbase
testC1.c -mmacosx-version-min=10.5.6 -mtune=generic -march=apple -
auxbase-strip src/testC1.o -g3 -O0 -Wall -version -fmessage-length=0 -
o /var/folders/s-/s-ktPSzyFXOv9RwyFeEsLk+++TM/-Tmp-//cc3Hve2w.s
ignoring nonexistent directory "/usr/lib/gcc/i686-apple-
darwin9/4.0.1/../../../../i686-apple-darwin9/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i686-apple-darwin9/4.0.1/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
GNU Objective-C version 4.0.1 (Apple Inc. build 5490) (i686-apple-
darwin9)
compiled by GNU C version 4.0.1 (Apple Inc. build 5490).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-
heapsize=131072
Compiler executable checksum: 55c67d4fa11c5c91e704fbca53628a89
../src/testC1.c: In function 'main':
../src/testC1.c:16: warning: implicit declaration of function 'NSLog'
/usr/libexec/gcc/i686-apple-darwin9/4.0.1/as -arch i386 -
force_cpusubtype_ALL -osrc/testC1.o /var/folders/s-/s-
ktPSzyFXOv9RwyFeEsLk+++TM/-Tmp-//cc3Hve2w.s
Finished building: ../src/testC1.c

Building target: testC1
Invoking: MacOS X C Linker
gcc -framework Foundation -o "testC1" ./src/testC1.o
Finished building target: testC1

On 18 Feb., 04:45, AlBlue <alex.blew...@gmail.com> wrote:
>
> If I rename it to .m, it doesn't get picked up as a source file to be
> compiled (unsurprisingly) but at least it shows CDT can be used to
> compile an Objective-C program with suitable massaging of the
> parameters.


for compiling a .m file, you must define "*.m" as a "C Source File" in
preferences => C/C++ General => File Types (=> Use project settings).
here's my output after I've done this:

Building target: testC1.m
Invoking: MacOS X C Linker
gcc -framework Foundation -o "testC1.m" ./src/testC1.o
Finished building target: testC1.m



Reply all
Reply to author
Forward
0 new messages