compiling objective-c with nvcc

I’ve got a small project that is written mostly in C++, but there’s one file (SDLMain.m) in Objective-C.

When I compile it with g++, it works fine. But when I try using nvcc, I get

nvcc fatal   : Don't know what to do with 'SDLMain.m'

How can I tell nvcc to just pass that on to g++ the same as it does with .cpp files?

OK, I found a solution.

My first approach to a solution was to compile the objective-c file using g++

$ g++ -c SDLMain.m

But then the linker had trouble putting the .o files together.

$ nvcc -o sdl_app *.o -lm -Xlinker -framework,SDL,-framework,Cocoa

ld: warning: in SDLMain.o, file was built for unsupported file format which is not the architecture being linked (i386)

Undefined symbols:

  "_main", referenced from:

	  start in crt1.10.6.o

	 (maybe you meant: _SDL_main)

ld: symbol(s) not found

collect2: ld returned 1 exit status

But what I just found, and what seems to work, is using g++ to compile for i386.

$ nvcc -I. -c main.cpp

$ g++ -arch i386 -I. -c SDLMain.m

$ nvcc -I. -O2 -o sdl_app *.o -lm -Xlinker -framework,SDL,-framework,Cocoa

And rolling that up into a Makefile works just fine.

OK, I found a solution.

My first approach to a solution was to compile the objective-c file using g++

$ g++ -c SDLMain.m

But then the linker had trouble putting the .o files together.

$ nvcc -o sdl_app *.o -lm -Xlinker -framework,SDL,-framework,Cocoa

ld: warning: in SDLMain.o, file was built for unsupported file format which is not the architecture being linked (i386)

Undefined symbols:

  "_main", referenced from:

	  start in crt1.10.6.o

	 (maybe you meant: _SDL_main)

ld: symbol(s) not found

collect2: ld returned 1 exit status

But what I just found, and what seems to work, is using g++ to compile for i386.

$ nvcc -I. -c main.cpp

$ g++ -arch i386 -I. -c SDLMain.m

$ nvcc -I. -O2 -o sdl_app *.o -lm -Xlinker -framework,SDL,-framework,Cocoa

And rolling that up into a Makefile works just fine.