installing objective c compiler - objective-c

i wanted to install objective c compiler for ubuntu.
this site was used to install GNUstep on ubuntu.
http://www.techotopia.com/index.php/Installing_and_Using_GNUstep_and_Objective-C_on_Linux
then commands were written in following order in terminal-
sudo apt-get install gnustep
sudo apt-get install gnustep-devel
then,i wrote my sample code and saved it as hello.m
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (#"hello world");
[pool drain];
return 0;
}
then,i typed in terminal
. /usr/share/GNUstep/Makefiles/GNUstep.
gcc `gnustep-config --objc-flags` -lgnustep-base hello.m -o hello
then,an error message appeared that
gcc: gnustep-config --objc-flags: No such file or directory
hello.m:1:23: fatal error: Foundation.h: No such file or directory
compilation terminated.
then,i wrote
sudo apt-get install gobjc
then,terminal showed
Reading package lists... Done
Building dependency tree
Reading state information... Done
gobjc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 205 not upgraded.
then,i again compiled but it showed again the same error.
hp#ubuntu:~$ gcc 'gnustep-config --objc-flags' -lgnustep-base hello.m -o hello
gcc: gnustep-config --objc-flags: No such file or directory
hello.m:1:23: fatal error: Foundation.h: No such file or directory
compilation terminated.
so,need some help..

Try running:
gnustep-config --objc-flags
on its own to check if it returns error or appropriate gcc flags, etc.
Also, try finding the location for the include dir and add it explicitly with -Idir option to gcc

Related

install ncurses extensions on php7.0

I try install ncurses extensions for php7.0 but I get this error
/bin/bash /tmp/pear/download/ncurses-1.0.2/libtool --mode=compile cc -I. -I/tmp/pear/download/ncurses-1.0.2 -DPHP_ATOM_INC -I/tmp/pear/download/ncurses-1.0.2/include -I/tmp/pear/download/ncurses-1.0.2/main -I/tmp/pear/download/ncurses-1.0.2 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/download/ncurses-1.0.2/ncurses.c -o ncurses.lo
libtool: compile: cc -I. -I/tmp/pear/download/ncurses-1.0.2 -DPHP_ATOM_INC -I/tmp/pear/download/ncurses-1.0.2/include -I/tmp/pear/download/ncurses-1.0.2/main -I/tmp/pear/download/ncurses-1.0.2 -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/download/ncurses-1.0.2/ncurses.c -fPIC -DPIC -o .libs/ncurses.o
/tmp/pear/download/ncurses-1.0.2/ncurses.c:36:37: error: unknown type name ‘zend_rsrc_list_entry’
static void ncurses_destruct_window(zend_rsrc_list_entry *rsrc TSRMLS_DC)
^
/tmp/pear/download/ncurses-1.0.2/ncurses.c:45:36: error: unknown type name ‘zend_rsrc_list_entry’
static void ncurses_destruct_panel(zend_rsrc_list_entry *rsrc TSRMLS_DC)
^
/tmp/pear/download/ncurses-1.0.2/ncurses.c: In function ‘zm_startup_ncurses’:
/tmp/pear/download/ncurses-1.0.2/ncurses.c:247:57: error: ‘ncurses_destruct_window’ undeclared (first use in this function)
le_ncurses_windows = zend_register_list_destructors_ex(ncurses_destruct_window, NULL, "ncurses_window", module_number);
^
/tmp/pear/download/ncurses-1.0.2/ncurses.c:247:57: note: each undeclared identifier is reported only once for each function it appears in
/tmp/pear/download/ncurses-1.0.2/ncurses.c:249:56: error: ‘ncurses_destruct_panel’ undeclared (first use in this function)
le_ncurses_panels = zend_register_list_destructors_ex(ncurses_destruct_panel, NULL, "ncurses_panel", module_number);
^
Makefile:194: ошибка выполнения рецепта для цели «ncurses.lo»
make: *** [ncurses.lo] Ошибка 1
ошибка выполнения рецепта для цели «ncurses.lo» is like error in process run target
There is a patch which can be applied against v1.0.2 of ncurses for php to modify it for php 7. Once the patch has been applied, the extension can be built and installed.
Required packages (these are Debian package names):
php-cli
php-pear
php-dev
libncurses5-dev
ncurses-doc
libncursesw5-dev
All following commands assume the user is logged in as root. Packaging commands are specific to Debian. These have been tested under Debian Stretch.
apt-get install php-cli php-pear php-dev libncurses5-dev ncurses-doc libncursesw5-dev
Use pecl to get v1.0.2 of ncurses, and wget to get the patch (as ncurses.patch).
cd /root
pecl download ncurses
mkdir /root/ncurses
cd /root/ncurses
tar -xvzf /root/ncurses-1.0.2.tgz
wget "https://bugs.php.net/patch-display.php?bug_id=71299&patch=ncurses-php7-support-again.patch&revision=1474549490&download=1" -O ncurses.patch
Rename the ncurses-1.0.2 directory to ncurses-php5 because that is the name which the patch expects, and apply the patch.
mv ncurses-1.0.2 ncurses-php5
patch --strip=0 --verbose --ignore-whitespace <ncurses.patch
Build the ncurses extension. This will build the ncurses.so file in /root/ncurses/ncurses-php5/modules.
cd ncurses-php5
phpize
./configure
make
Install the ncurses extension. This will place the ncurses.so file in /usr/lib/php/20151012. This location may differ in other distributions.
make install
Make the ncurses.so extension available to php 7. These file locations may differ in other distributions.
cat <<'EndOfHereDoc' >/etc/php/7.0/mods-available/ncurses.ini
; configuration for php ncurses module
; priority=20
extension=ncurses.so
EndOfHereDoc
ln --symbolic /etc/php/7.0/mods-available/ncurses.ini /etc/php/7.0/cli/conf.d/20-ncurses.ini
Verify that ncurses is indeed available.
php -m | grep ncurses
Once everything is working, the /root/ncurses directory, /root/ncurses-1.0.2.tgz file, and /root/channels.xml file can be removed.
I had the same problem and stumbled upon this topic. Soluthions provided here didn't work for me, but I found another solution, whitch is available here: https://github.com/OOPS-ORG-PHP/mod_ncurses
It is patched and ready to compile.
Just sharing with others that will struggle with this as I did.

Objective C compiling with clang on Linux Foundation/Foundation.h linking: file not found

I'm trying to compile a program in Objective C on Ubuntu, I have installed GNUstep, set all the GNUSTEP_* environment variables, and installed clang, because I read that gcc can't compile Objective-C code with blocks (Objective-C 'anonymous' functions, just to be clear: ^ { }).
What I get when I run this command:
clang hello.m -o hello
Is:
hello.m:1:9: fatal error: 'Foundation/Foundation.h' file not found
#import <Foundation/Foundation.h>
^
1 error generated.
I tried this also:
clang -L '/usr/include/GNUstep/Foundation/Foundation.h' hello.m -o hello
Where /usr/include/... is the path to the Foundation.h file on my system; but I still get the same result.
How can I link those header files automatically and compile Objective-C?
Thanks!
You can use gnustep-config:
clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` hello.m -o hello

How to load dll or lib files in LLVM?

I am new to LLVM. I built LLVM and Clang on windows by GnuStep yesterday.
LLVM+CLang:3.2
GCC:4.6.1(GnuStep)
OS:Win7 64
I can compile Objective-c source file to both bitcode and exe. The exe works, but when I tried to execute the bitcode, I got this error:
LLVM ERROR: Could not resolve external global address:
_OBJC_CLASS_NSConstantString
Questions:
How can I load dll or lib files in llvm?
How can I link lib files(ex: libobjc.dll.a) to bitcode? Is that possible?
hello.m
#import <Foundation/Foundation.h>
int main(int argc, char**argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(#"Hello Objective-C\n");
[pool release];
return 0;
}
Makefile
CC=gcc
CCFLAGS=-fconstant-string-class=NSConstantString -ID:/GNUstep/GNUstep/System/Library/Headers
LDFLAGS=-LD:/GNUstep/GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base
CLANG=clang
CLANG_FLAG=-c -fobjc-runtime=gcc -emit-llvm
LLC=llc
LLI=lli
LLI_FLAG=-load=D:\GNUstep\GNUstep\System\Tools\objc-4.dll -load=D:\GNUstep\GNUstep\System\Tools\gnustep-base-1_24.dll
#LLI_FLAG=-load=D:\GNUstep\GNUstep\System\Library\Libraries\libgnustep-base.dll.a -load=D:\GNUstep\GNUstep\System\Library\Libraries\libobjc.dll.a
all:hello.obj hello1.exe
hello.exe: hello.o
$(CC) -o hello.exe hello.o $(LDFLAGS)
hello.obj: hello.bc
$(LLC) -filetype=obj hello.bc
hello.bc:hello.m
$(CLANG) -o hello.bc hello.m $(CLANG_FLAG) $(CCFLAGS)
hello1.exe: hello.m
$(CLANG) hello.m -o hello1.exe $(CCFLAGS) $(LDFLAGS)
run:
#Err
$(LLI) $(LLI_FLAG) -force-interpreter=false hello.bc
#OK
hello.exe
#OK
hello1.exe
clean:
rm *.o
rm *.exe
rm *.bc
You likely need at least one hard, static reference to a symbol in each DLL. In your main(), try adding [NSConstantString class]; (add a declaration, if needed).
The windows dynamic linker is quite proactive about not loading DLLs without a hard symbol reference. This conflicts with Objective-C's dynamic lookup.
(This is a guess based on experience. Been a decade since I've done ObjC on Windows, but seemingly little has changed.)

How to compile objc code on Linux?

Assuming you have your .h and .m ready on a Linux server, which command would you issue to GCC to have it compiled?
The relevant parts:
gcc -c -Wno-import List.m
gcc -o prog -Wno-import List.o main.o -lobjc
. . . make sure that the Objective-C library and header files (objc/Object.h) were installed when gcc was built.
Note that when linking Objective-C with gcc, you need to specify the Objective-C library by using the -lobjc switch.
See this link for more information.
Additional link with possible solution to the missing compiler issue:
Try installing either gobjc++ or gobjc
sudo apt-get install gobjc++
gcc -x objective-c file.m -o out
Google is your friend

How do I compile a GNUstep application that uses NSApplication on Windows?

I am exploring with compiling an application with GNUstep on Windows. This is my main.m file:
#import <???/???.h>
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSApplication sharedApplication];
[pool release];
}
I realize this is an incomplete fragment to say the least and it obviously won't do anything. I have tried several different import statements including Cocoa/Cocoa.h, GNUstepGUI/GMAppKit.h, etc. But I always run into errors with compiling that I can't seem to find help with online.
This is my compile command, which I am running from the mingw shell:
gcc -o test main.m -I /GNUstep/System/Library/Headers/ \
-L /GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base \
-fconstant-string-class=NSConstantString -enable-auto-import
These are the errors I get:
c:/WINDOWS/TEMP/ccHxKZG2.o:main.m(.data+0x390): undefined reference to
'___objc_class_name_NSApplication'
collect2:ld returned 1 exit status
Any ideas on what I need to #import, or what needs fixing in my compile command?
Thanks!
Thanks to Peter Hosey I was able to Google myself to the page with the answer:
http://psurobotics.org/wiki/index.php?title=Objective-C
Unlike OS X development, you need a "makefile":
Put this into a file called "GNUmakefile" in the same directory as your source:
include $(GNUSTEP_MAKEFILES)/common.make
APP_NAME = MyAppName
MyAppName_HEADERS =
MyAppName_OBJC_FILES = main.m
MyAppName_RESOURCE_FILES =
include $(GNUSTEP_MAKEFILES)/application.make
Then execute make
The page says to execute openapp ./MyAppName.app but the .exe file within the .app folder appears to run on its own.
That's a linker error. #import is a preprocessor directive; it won't solve an error in linking, and you wouldn't have gotten as far as linking if you'd had a preprocessor error, anyway.
You need to link against Foundation and AppKit (especially the latter, for NSApplication), or whatever GNUstep's equivalents are.
Under Linux, you can compile with gcc :
gcc ``gnustep-config --objc-flags --gui-libs`` -o main main.m -L /usr/include/GNUstep/ -lobjc -lgnustep-base -lgnustep-gui