Link with GNUstep on Ubuntu 14.04, 64 bit - objective-c

I am attempting to compile a simple application that references GNUstep classes, with GNUstep on my Ubuntu 14.04, 64 bit, machine:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int main(int argc, char **argv)
{
NSString *bestType = [[NSPasteboard generalPasteboard]
availableTypeFromArray: nil];
NSLog(#"best type: %#", bestType);
return 0;
}
Here are my compile and link flags (some of which may be overkill):
CFLAGS=`gnustep-config --objc-flags` -std=gnu99
LDFLAGS=`gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL
Before compilation I ran the script:
/usr/share/GNUstep/Makefiles/GNUstep.sh
And here is the output from 'make -n'
gcc main.m `gnustep-config --objc-flags` -std=gnu99 -L. `gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL -o tester
But when linking, Cocoa classes seem to not be pulled in, and I get an undefined reference error:
/tmp/ccnyXBoH.o:(.data.rel+0x8): undefined reference to `__objc_class_name_NSPasteboard'
If I remove all references to Cocoa classes in main.m, the app compiles without error.

The reason why you can't find the class definition for NSPasteboard is because it's in the gnustep-config --gui-libs options - i.e. the symbol is in the gui library of GNUStep, not in the base library of GNUStep. The solution is to change the LDFLAGS line to:
LDFLAGS=`gnustep-config --gui-libs` -lglut -lGLU -lGL
You shouldn't need to double-specify -lgnustep-base -lobjc -lm - they're part of both --base-libs and --gui-libs.

Related

invoke framework in termimal the window seems to be blocked

now ,I have a framework named "MyFramework.framework" which include a window.nib, and I write a example to invoke it in terminal.
code:
//<MyFramework/myUI.h>
#ifndef Frmwork_myUI_h
#define Frmwork_myUI_h
#ifdef __cplusplus
extern "C"{
#endif
void ShowDialog();
#ifdef __cplusplus
}
#endif
#endif
//test.mm
#include <MyFramework/myUI.h>
#include <Foundation/NSRunLoop.h>
int main(int argc, char *argv[])
{
ShowDialog() ;
while (!isTransmitCompleted)
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
return 0;
}
//build test.mm
g++ -c test.mm -o test.o
g++ test.o -o test -lpthread -framework Cocoa -framework AppKit -framework CoreData -framework Foundation -framework MyFramework
//run
$./test
the Dialog can appear, but it seems be blocked ,it has no focus , I can not input anything, I can do nothing ,what is wrong?
now , I got the solution.
In OS X 10.6 ,I write a npapi plugin for Safari, In this plugin I invoke an framework which shows a Modal Window to get password. after close this modal window ,the Safari seems to block.
In my framework , I show this modal window by runModalForWindow function ,when I change to runModalSession , everything works perfectly. I don`t know why but it really works for me .

objective c libraries on ubuntu

I installed GNUStep on Ubuntu 12.10, and some tools for Objective-C development. I then tried to compile the following code.
#import <Foundation/Foundation.h>
int main(int *argc, const char *argv[]) {
NSAutorelease *pool = [[NSAutorelease alloc] init];
NSLog(#"hello world");
[pool drain];
return 0;
}
When I compile it with gcc -o hello hello.m -Wall -lobjc, I get the following error.
Foundation/Foundation.h: No such file or directory; compilation terminated.
I find the Foundation library and other libraries in /usr/include/GNUstep/Foundation. Why am I getting that error message?

Try to integrate LinkedIn in iPhone application

I have download the source from https://github.com/ResultsDirect/LinkedIn-iPhone . Demo working fine, and try to use in my application.
I have followed all the steps already whatever required as mention here in post ...
But I have getting the error
"_OBJC_CLASS_$_RDLinkedInEngine", referenced from:
"_OBJC_CLASS_$_RDLinkedInAuthorizationController", referenced from:
When I comment the lines of RDLinkedInEngine and RDLinkedInAuthorizationController then error are removed
- (void)loadView {
[super loadView];
// rdEngine = [[RDLinkedInEngine engineWithConsumerKey:kOAuthConsumerKey consumerSecret:kOAuthConsumerSecret delegate:self] retain];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// if( !rdHasAppeared ) {
// UIViewController* controller = [RDLinkedInAuthorizationController authorizationControllerWithEngine:rdEngine delegate:self];
// if( controller ) {
// [self presentModalViewController:controller animated:YES];
// rdHasAppeared = YES;
// }
// else {
// NSLog(#"Already authenticated");
// }
// }
}
I my application I have already integrated MGTwitterEngine from source https://github.com/bengottlieb/Twitter-OAuth-iPhone Which is wokring ok.
Amit Battan
most probably you need to add some static library (.a file)... or src folder itself from linkedIn source...
I have gone through the same issue. It can be solved by setting Library Dependency. Select project target and then select general. There you will find Direct dependencies. Add LinkedInLibrary from LinkedInClientLibrary.xcodeProject
#mihir
Build butterfli of project butterfli with configuration Debug
CompileC build/butterfli.build/Debug-iphonesimulator/butterfli.build/Objects-normal/i386/butterfliViewController.o /Users/pratgupta/Desktop/butterfli/Classes/butterfliViewController.m normal i386 objective-c com.apple.compilers.gcc.4_2
cd /Users/pratgupta/Desktop/butterfli
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -x objective-c -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -fexceptions -fvisibility=hidden -mmacosx-version-min=10.6 -gdwarf-2 -fobjc-abi-version=2 -fobjc-legacy-dispatch -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -iquote /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-generated-files.hmap -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-own-target-headers.hmap -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-all-target-headers.hmap -iquote /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-project-headers.hmap -F/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator -iquote/Users/pratgupta/Desktop/butterfli/LinkedInClientLibrary -I/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator/include -I/Users/pratgupta/Desktop/butterfli/OAuthConsumeriPhoneLib -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/usr/include/libxml2 -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/DerivedSources/i386 -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/DerivedSources -include /var/folders/RE/RE2wCP+eEqaZg4J2Og3nmE+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/butterfli_Prefix-aeetprdcvcynktfkafjmijthtlhp/butterfli_Prefix.pch -c /Users/pratgupta/Desktop/butterfli/Classes/butterfliViewController.m -o /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/Objects-normal/i386/butterfliViewController.o
/Users/pratgupta/Desktop/butterfli/Classes/butterfliViewController.m:321: warning: property 'fbPermissions' requires method '-fbPermissions' to be defined - use #synthesize, #dynamic or provide a method implementation
Ld build/Debug-iphonesimulator/butterfli.app/butterfli normal i386
cd /Users/pratgupta/Desktop/butterfli
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -L/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator "-L/Users/pratgupta/Desktop/butterfli/Twitter+OAuth/Libraries & Headers" -F/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator -filelist /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/Objects-normal/i386/butterfli.LinkFileList -mmacosx-version-min=10.6 -all_load -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -lOAuth -lxml2 /Users/pratgupta/Desktop/butterfli/LinkedInClientLibrary/build/Debug-iphonesimulator/libLinkedInClientLibrary.a -o /Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator/butterfli.app/butterfli
ld: duplicate symbol _EstimateBas64EncodedDataSize in /Users/pratgupta/Desktop/butterfli/LinkedInClientLibrary/build/Debug-iphonesimulator/libLinkedInClientLibrary.a(Base64Transcoder.o) and /Users/pratgupta/Desktop/butterfli/Twitter+OAuth/Libraries & Headers/libOAuth.a(Base64Transcoder.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

compiling Objective-C on Ubuntu using GCC

ok i have this program here:
int main(int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (#"Hello world!");
[pool drain];
return 0;
}
the problem is when i compile it with the command
"gcc -framework Foundation prog1.m -o prog1"
i get this:
"gcc: error trying to exec 'cclobj' : execvp: No such file or Directory"
do i need to install any packages??
"
Its not the only way but GNUStep worked for me. For a good writeup on setting it up look here.
Note: Your exact error is listed about halfway down that page. Your missing package seems to be 'gobjc'.
You need to install "gobjc"
Example
gcc -x objective-c -o
check this link Compiling Objective-C using the gcc
http://webcache.googleusercontent.com/search?q=cache:iIgkFc-JoRYJ:https://www.cs.indiana.edu/classes/c304/ObjCompile.html+http://www.it.uc3m.es/mibanez/lao/lab1/tutorial3/ObjCompile.html&cd=1&hl=en&ct=clnk&client=safari

How to compile an objective c program under windows with independant MingW

I know how to compile the objective c program using gnustep version of mingw.
But I don't like their shell and I want to use the standard mingw gcc compiler.
I put this gcc bin directory in environment path of course, open command prompt in my helloworld.m directory
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (#"Hello World!");
[pool drain];
return 0;
}
and type
gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString
but it doesn't work because it cannot find foundation/foundation.h
How to fix this and if possible avoid hardcoding in hello source code ?
Have a look here at the end of the post the blogger says to write:
gcc `gnustep-config --objc-flags` -o hello2 hello2.m -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base
It seems like you always have to pass through GNUStep
I had the same problem.Modifying command line like below solved my problem.
gcc -I"c:/GNUstep/GNUstep/System/Library/Headers" -L "c:/GNUstep/GNUstep/System/Library/Libraries" -o hello hello.m -lobjc -lgnustep-base -fconstant-string-class=NSConstantString