I am writing an Objective C program to log and I am using Ubuntu to compile it.
While compiling, I am getting error as
/tmp/ccJKC2MN.o:(.data+0x150): undefined reference to
`__objc_class_name_AbcLogger'
I have linked all my header files at the starting of each class.
My program:
Logger.h
Logger.m
AbcLogger.h
AbcLogger.m
example.m
To compile it I am using the command:
gcc -x objective-c -I/usr/include/GNUstep \
-fconstant-string-class=NSConstantString \
-D_NATIVE_OBJC_EXCEPTIONS \
Logger.h AbcLogger.h example.m -lgnustep-base -o human
Can you please help me with the issue. Ask for the code if you need it.
My suggestion would be to make a GNUmakefile
I can't say if this is 100% accurate because I can't be sure of this program setup, but I would write one like this:
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME=human
human_OBJC_FILES=\
Logger.m\
AbcLogger.m\
example.m
human_HEADERS=\
Logger.h\
AbcLogger.h
include $(GNUSTEP_MAKEFILES)/tool.make
you will need GNUSTEP_MAKEFILES to lead to the GNUstep/Makefiles path so if it spits out an error like "Can't find common.make" make sure you run
export GNUSTEP_MAKEFILES=/(Where ever you GNUstep folder is)/Makefiles
just type
make
GOOD LUCK!
Related
I am trying to compile a simple hello world program written in objective c from ubuntu but I am getting an error as
gcc: error: unrecognized command line option ‘-fobjc-nonfragile-abi’
To compile I am using the command
gcc gnustep-config --objc-flags -lgnustep-base hello.m -o hello
Can you please help me out with this. I am not getting any solution in google too.
The best way to compile gnustep code is with makefiles. It avoids all this faff with GCC:
make a file called GNUmakefile
Make the content:
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME=hello
hello_OBJC_FILES=hello.m
include $(GNUSTEP_MAKEFILES)/tool.make
just type:
make
to compile, the output is in the obj/ dir
I would give this a read
http://www.gnustep.it/nicola/Tutorials/WritingMakefiles/
Now a problem I always have is it can't find the gnustep makefiles.
The long term fix is to add it to path, the quick fix is every session, type:
export GNUSTEP_MAKEFILES=/usr/share/GNUstep/Makefiles
/usr/share/GNUstep/Makefiles is my gnustep makefile dir, YOURS MAY BE DIFFERENT! but I assume that this is the dir if you installed gnustep like this:
apt-get install gnustep gnustep-devel
it may be worth making sure you have the gnustep-devel package!
Good luck!
I am a newbie to Objective C programs. I'm learning to code from tutorialspoint.com
As mentioned therein I downloaded GNUstep (Windows).
First, installed the MSYS/MinGW System package and then core package.
After that followed the steps mentioned there. I created a simple program with name hello.m and Stored that in C drive (Snapshot 1)
I don't know the meaning of this command below but entered it:
$ gcc gnustep-config --objc-flags -L /GNUstep/System/Library/Libraries hello.m -o hello -lgnustep-base -lobjc
The error it shows is - sh: gcc: command not found
Please help with the same, to compile and run my first Objective C program
gcc is the compiler, the other parameters are for compiling objective-c code.
Apparently you have misconfiguration in MSYS/MinGW setup.
Check out following post which has alternative and easier solution for running gcc under Windows.
I am compiling a project in Vala and GTK +... In the compiler I pass options "-X -lm" corresponding to GLib.Math.
I'm already using glib-2.0 package but not know to spend those options through the CMakeList.txt file.
currently I run the following command to compile:
$ valac --pkg glib-2.0 main.vala -X -lm -o app
everything perfect, but not know how to make CMakeList.txt compile with these options "-X -lm"
Somebody give me a hand with this? Thousand thanks!
PS: Sorry for my bad English
SOLUTION:
add following line or modify if exist:
link_libraries(${DEPS_LIBRARIES} -lm)
You don't want to pass -X -lm to valac—when using a build system like CMake or autotools, typically the build system first converts the Vala code to C (valac -C), then hooks into the existing architecture for compiling the C. What you want to do is tell CMake to link to libm, which you probably want to use target_link_libraries for. Something like target_link_libraries(target_name m).
I'm learning Objective-C language. Since I don't have a Mac, I'm compiling and running my code within Ubuntu 11.04 platform.
Until now, I was using gcc to compile. I've installed GNUStep and all was working. But then I started to try some Objective-C 2.0 features, like #property and #synthesize, that gcc does not allow.
So I tried to compile the code with Clang, but it seems that it is not correctly linking my code with the GNUStep libraries, not even with a simple Hello world program.
For example, if I compile the following code:
#import <Foundation/Foundation.h>
int main(void) {
NSLog(#"Hello world!");
return 0;
}
The output of the compiler is:
/tmp/cc-dHZIp1.o: In function `main':
test.m:(.text+0x1f): undefined reference to `NSLog'
/tmp/cc-dHZIp1.o: In function `.objc_load_function':
test.m:(.text+0x3c): undefined reference to `__objc_exec_class'
collect2: ld returned 1 exit status
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
The command I'm using to compile is
clang -I /usr/include/GNUstep/ test.m -o test
with the -I directive to include the GNUStep libraries (otherwise, Clang is not able to find Foundation.h).
I've googled my problem, and visited both GNUStep and Clang web pages, but I haven't found a solution to it. So any help will be appreciated.
Thanks!
The problem was that the library gnustep-base was not being used by the linker. So the solution to this was using the option -Xlinker, that sends arguments to the linker used by clang:
clang -I /usr/include/GNUstep/ -Xlinker -lgnustep-base test.m -o test
The statement "-X linker -lgnustep-base" made the magic. However, I had problems with this command related to the class that represents a string in Objective-C:
./test: Uncaught exception NSInvalidArgumentException, reason: GSFFIInvocation:
Class 'NXConstantString'(instance) does not respond to forwardInvocation: for
'hasSuffix:'
I could solve it adding the argument "-fconstant-string-class=NSConstantString":
clang -I /usr/include/GNUstep/ -fconstant-string-class=NSConstantString \
-Xlinker -lgnustep-base test.m -o test
In addition, I've tried with some Objective-C 2.0 pieces of code and it seems to work.
Thank you for the help!
You can try gcc compiler:
First of all install GNU Objective-C Runtime: sudo apt-get install gobjc
then compile: gcc -o hello hello.m -Wall -lobjc
You are not able to use ObjC 2.0 features because you're missing a ObjC-runtime supporting those. GCC's runtime is old and outdated, it doesn't support ObjC 2.0. Clang/LLVM doesn't have a acompanied runtime, you need to install the ObjC2-runtime from GNUstep (which can be found here: https://github.com/gnustep/libobjc2 ) and reinstall GNUstep using this runtime.
Here are some bash scripts for different Ubuntu versions, that do everything for you:
http://wiki.gnustep.org/index.php/GNUstep_under_Ubuntu_Linux
And please don't try to reinvent GNUstep make, instead, use it:
http://www.gnustep.org/resources/documentation/Developer/Make/Manual/gnustep-make_1.html
If you really don't think so, here is some excerpt from there:
1.2 Structure of a Makefile
Here is an example makefile (named GNUmakefile to emphasis the fact that it relies on special features of the GNU make program).
#
# An example GNUmakefile
#
# Include the common variables defined by the Makefile Package
include $(GNUSTEP_MAKEFILES)/common.make
# Build a simple Objective-C program
TOOL_NAME = simple
# The Objective-C files to compile
simple_OBJC_FILES = simple.m
-include GNUmakefile.preamble
# Include in the rules for making GNUstep command-line programs
include $(GNUSTEP_MAKEFILES)/tool.make
-include GNUmakefile.postamble
This is all that is necessary to define the project.
In your case replace all occurrences of simple with test and you're done
1.3 Running Make
Normally to compile a package which uses the Makefile Package it is purely a matter of typing make from the top-level directory of the package, and the package is compiled without any additional interaction.
When I compiled an Objective-C code on Windows, I got this error.
$ gcc -o abc main.m
In file included from MyClass.m:2,
from main.m:2:
myclass.h:1:32: Foundation/NSObject.h: No such file or directory
In file included from MyClass.m:2,
from main.m:2:
myclass.h:4: error: syntax error before '(' token
myclass.h:6: error: cannot find interface declaration for `NSObject', superclass of `myclass'
Why is that? How can I fix this?
Thanks to initiate my help dear frnds
i hv just got the answer after posting this question. so the command to compile in window environment is this..
gcc `gnustep-config --objc-flags` -o myf main.m -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base
thanks for all.
You say you're on Windows. Do you in fact have an environment (such as GNUstep or Cocotron) that would give you the Foundation framework installed and set up correctly? Because I would guess not, and not having Foundation would indeed lead to errors about not having Foundation.