Cant find Foundation/NSObject.h in Linux while build Obj-c Program - objective-c

I was just starting to study obj-c on Ubuntu Linux today, the tutorial that I followed is http://www.otierney.net/objective-c.html, when I typed in the code that requires for Foundation/NSObject.h, the error appeared:
Fraction.h:1: fatal error: Foundation/NSObject.h: No such file or directory
and i searched for the solutions, and found a proper one
gcc -o Fraction -I/usr/GNUstep/System/Library/Headers
-L/usr/GNUstep/System/Library/Libraries
Fraction.m
-ldl
-lobjc
I tried this, but I found that I cannot find Headers under the Library directory. (My folder of GNUstep is /usr/share/GNUstep).
Does anyone know how to achieve the Headers?
I installed all the dev packages related to GNUstep but still no luck.
Hope I state my question clear enough. Sorry for my English.

Try with gnustep-config
gcc `gnustep-config --objc-flags` \
`gnustep-config --objc-libs` Fraction.m -o Fraction

GNUStep uses a fairly involved set of gmake macros - I wouldn't expect a simple command-line invocation of gcc to work very well, although to be honest I haven't tried that way myself. I found Nicolo Pera's tutorial and the project's own reference page to be quite useful when learning how to write make files for use with GNUStep.

In my case, compiling SOPE on CentOS 7, installed
yum install gnustep-base-devel
This solved the problem.

In my case, I installed gnustep-base to fix this error:
yum install gnustep-base

Related

Raspberry Pi -fatal error: sys/cdefs.h: No such file or directory

I'm trying to compile gcc5.3.0 on my Raspberry Pi with latest Raspbian system image.
$ ./configure --enbale-checking=release --enable-languages=c,c++,fortran --host=arm-cortexa7_neon-linux-gnueabihf --build=arm-cortexa7_neon-linux-gnueabihf --target=arm-cortexa7_neon-linux-gnueabihf
$ make
However, the original compiler (gcc4.9) complains about not founding sys/cdefs.h when compiling libgcc.
I checked I have libc6-dev and build-essential installed.
So I used grep -R 'cdefs' /usr/include/ to search it and I found it at /usr/include/bsd/. I created the sys directory and made hard links to these headers under /usr/include/bsd/sys.
This time it gave me a more weird error,
/usr/include/stdio.h:312:8: error: unknown type name 'FILE'.
I searched this on stackoverflow, and there's a similar question, https://stackoverflow.com/a/21047237/5691005. But when I removed /usr/include/sys and /usr/include/bsd, then reinstalled libc6-dev, I cannot find sys/cdefs.h under /usr/include, and the compiler gave errors still.
I'm now totally lost. Any suggestion will be appreciated.
I had similar problem with compiling gcc-8.2. I tried to do as described here with reinstalling:
sudo apt-get --reinstall install libc6 libc6-dev
After that I was locating all missing headers:
find / -name cdefs.h
and copying them to /usr/include:
those steps allowed only to move forward but I still didn't manage to completely build gcc.
The best solution I found is to download compiled version of gcc-8.1 from:
https://solarianprogrammer.com/2017/12/07/raspberry-pi-raspbian-compiling-gcc/
I also ran into this problem when creating a containerized build environment for cross-compiled Qt applications for raspberry pi 4.
I found I needed to edit the mkspec for the linux-rasp-pi4-v3d device and add another cflag so that gcc could find the header from my Raspi sysroot that was used to cross-compile Qt.
Specifically under qtbase/mkspecs/devices/linux-rasp-pi4-v3d-g++/qmake.conf:
QMAKE_CFLAGS = -march=armv8-a -mtune=cortex-a72 -mfpu=crypto-neon-fp-armv8 -I$$[QT_SYSROOT]/usr/include/arm-linux-gnueabihf

Getting error while compiling objective-c in ubuntu

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!

Objective C program Compilation and Execution

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.

How to specify c++0x flag on cent os

The command g++ -o myprogram myprogram.c -std=c++0x works well on ubuntu but when I try the same with centos it throws me an error cc1plus: error: unrecognized command line option "-std=c++0x". Even google doesn't give the answer. Have anybody experienced it before? Does anybody know the solution?
You most likely have different versions of the compiler on each system, run g++ --version to see which version you're running on each (-std=c++0x is only supported from version 4.4 of g++).
In the CentOS repositories is something called g++44. Yum it, or grab it however makes the most sense to you.
Then, when you build, use g++44... with the rest of your switches. That might help, you never know.
If it works for you then you could remove g++ and symlink g++44.

Foundation/NSObject.h: No such file or directory what the reason on windows

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.