GNUSetup objective-c , can't find libxml/tree.h' file not found - objective-c

i trying to use libxml2 in GNUsetup in windows using objective-C
compiling with clang.
it keeps giving me the error:
$ make CC=clang
This is gnustep-make 2.6.2. Type 'make print-gnustep-make-help' for help.
Making all for tool sample_app...
Compiling file HtmlParser.m ...
In file included from HtmlParser.m:1:
./HtmlParser.h:2:9: fatal error: 'libxml/tree.h' file not found
#import <libxml/tree.h>
^
1 error generated.
make[3]: *** [obj/sample_app.obj/HtmlParser.m.o] Error 1
make[2]: *** [internal-tool-all_] Error 2
make[1]: *** [sample_app.all.tool.variables] Error 2
make: *** [internal-all] Error 2
the files do existe in :c:\GNUstep\include\libxml2\libxml\
this is my GNUsetup file which compiles the files
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = sample_app
sample_app_HEADERS = HttpManager.h UT.h HtmlParser.h
sample_app_OBJC_FILES = main.m HttpManager.m UT.m HtmlParser.m
sample_app_RESOURCE_FILES =
include $(GNUSTEP_MAKEFILES)/tool.make
and this is my file that include the libxml2 headers
#import <Foundation/Foundation.h>
#import <libxml/tree.h>
#import <libxml/parser.h>
#import <libxml/HTMLparser.h>
#import <libxml/xpath.h>
#import <libxml/xpathInternals.h>
#interface HtmlParser
{
NSString* encoding;
}
-(id)init
{
self = [super init];
if(self) {
encoding = #"UTF-8";
}
return self;
}
-(void)ExtractInnerSiteLinks:(NSString*) PageHtml:(NSString*) url;
#end

You can try to add more flags into GNUmakefile eg.
ADDITIONAL_INCLUDE_DIRS += c:\GNUstep\include\libxml2\ .. well I don't really know how to specify a path in a makefile on Windows..
may be you will have linking problem, play with
ADDITIONAL_LIB_DIRS += -L*your dll path..*
ADDITIONAL_OBJC_LIBS += -lxml2

Related

CocoaLumberjack - change log file name by subclassing the LogFileManager

I am trying to change the logfile name. What i've found so far is this.
My subclass of DDLogFileManagerDefault looks like this:
LogFileManager.h
#import CocoaLumberjack;
// this import would work as well
// #import <CocoaLumberjack/CocoaLumberjack.h>
// but none of these
//#import "DDLog.h"
//#import "DDTTYLogger.h"
//#import "DDASLLogger.h"
//#import "DDFileLogger.h"
#interface LogFileManager : DDLogFileManagerDefault
#end
LogFileManager.m
#import "LogFileManager.h"
#implementation LogFileManager
- (NSString *)newLogFileName {
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
NSString *appName = [info objectForKey:#"CFBundleExecutable"];
NSString *timeStamp = [self getTimestamp];
return [NSString stringWithFormat:#"%#%#.log", appName, timeStamp];
}
- (BOOL)isLogFile:(NSString *)fileName {
return NO;
}
- (NSString *)getTimestamp {
static dispatch_once_t onceToken;
static NSDateFormatter *dateFormatter;
dispatch_once(&onceToken, ^{
dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:#"YYYY.MM.dd-HH.mm.ss"];
});
return [dateFormatter stringFromDate:NSDate.date];
}
#end
This is how I use it:
DDLogFileManagerDefault *documentsFileManager = [[LogFileManager alloc] init];
DDFileLogger *fileLogger = [[DDFileLogger alloc] initWithLogFileManager:documentsFileManager];
When I replace LogFileManager with DDLogFileManagerDefault it works fine. Otherwise I get:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_LogFileManager", referenced from:
objc-class-ref in Logger.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code
1 (use -v to see invocation)
What exactly am I missing here?
CocoaLumberjack is added via Carthage 3.2.0 for Xcode 8.
I've added the CocoaLumberjack.framework to the Build Phases like all the other frameworks in the project with /usr/local/bin/carthage copy-frameworks
Okay, I solved it. That error was very confusing but has nothing to do with anything. Sorry for that.
It is a big project with lots of build targets and lots of compile flags that make different things throw a warning and warnings become an error. In this case I added flags to disable the global ones to the mentioned Logger.m class. But I only added those anti-flags to one target and forgot to add them to another. That's why it didn't build.
Still strange, that the compiler didn't simply say: cannot build target A or compile error in file B. Instead I got a missing architecture message that was misleading me totally... So sorry for the trouble. Fixed it.

Objective-C compilation with makefile yielding unexpected errors?

Following "Programming in Objective-C (6th Edition) shows this Hello World
#import <Foundation/Foundation.h>
int main(void)
{
#autoreleasepool
{
NSLog(#"Programming is fun!");
}
return 0;
}
When I try to compile the program using a GNUStep makefile
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = Hello
Hello_OBJC_FILES = hello.m
include $(GNUSTEP_MAKEFILES)/tool.make
I get errors such as
hello.m: In function 'main':
hello.m:5:2: error: stray '#' in program
hello.m:5:3: error: 'autoreleasepool' undeclared (first use in this function)
hello.m:5:3: note: each undeclared identifier is reported only once for each function it appears in
hello.m:5:19: error: expected ';' before '{' token
hello.m:9:1: warning: control reaches end of non-void function [-Wreturn-type]
make[3]: *** [obj/Hello.obj/hello.m.o] Error 1
make[2]: *** [internal-tool-all_] Error 2
make[1]: *** [Hello.all.tool.variables] Error 2
make: *** [internal-all] Error 2
Am I doing something wrong? I can't see any bugs in the program and I'm not sure why the makefile wouldn't work.
I should add I am running on Windows 10
I found the problem after reading this (http://gnustep.8.n7.nabble.com/getting-error-autoreleasepool-undeclared-first-use-in-this-function-td32251.html)
Turns out using #autoreleasepool {} is syntactic sugar for
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// do your stuff
[pool drain];
This old method is the only one supported by GCC, you will have to switch to clang to use Objective-C 2.0.

error: cannot find interface declaration for ‘NSAttributedString’ with GNUStep

I have been messing around with GNUStep, and I have a simple main.m, which compiles fine. I wanted to see if objective-c libraries (meant for ios/mac) work with GNUStep, so i downloaded JSONKit and tried to compile that, but I keep getting this error:
mark#Emperor:~/objc-test2$ make
This is gnustep-make 2.6.2. Type 'make print-gnustep-make-help' for help.
Making all for tool Test...
Compiling file JSONKit.m ...
In file included from JSONKit.m:110:0:
JSONKit.h:63:21: warning: "/*" within comment [-Wcomment]
In file included from /usr/include/GNUstep/Foundation/NSAttributedString.h:143:0,
from /usr/include/GNUstep/Foundation/Foundation.h:42,
from JSONKit.h:72,
from JSONKit.m:110:
/usr/include/GNUstep/GNUstepBase/NSAttributedString+GNUstepBase.h:44:1: error: cannot find interface declaration for ‘NSAttributedString’
make[3]: *** [obj/Test.obj/JSONKit.m.o] Error 1
make[2]: *** [internal-tool-all_] Error 2
make[1]: *** [Test.all.tool.variables] Error 2
make: *** [internal-all] Error 2
mark#Emperor:~/objc-test2$
my main.m is this:
mark#Emperor:~/objc-test2$ cat main.m
#import <stdio.h>
#include <Foundation/Foundation.h>
#import "Fraction.h"
#import "JSONKit.h"
int main( int argc, const char *argv[] ) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// create a new instance
Fraction *frac = [[Fraction alloc] init];
// set the values
[frac setNumerator: 1];
[frac setDenominator: 3];
// print it
NSLog(# "The fraction is: %#", [frac print]);
// free memory
[frac release];
NSMutableArray *testArr = [[NSMutableArray alloc] initWithCapacity:0];
[testArr addObject:[NSNumber numberWithInt:2]];
[testArr addObject:#"Hey"];
NSLog([testArr JSONString]);
[pool drain];
return 0;
}
mark#Emperor:~/objc-test2$
I've googled around and I have made sure that i have the GNUStep env variables set, and i'm using a make file (taken from examples online)
mark#Emperor:~/objc-test2$ cat GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = Test
Test_OBJC_FILES = main.m Fraction.m JSONKit.m
Test_CPPFLAGS = $(RUNTIME_DEFINE)
# Include in the rules for making Objective-C programs
include $(GNUSTEP_MAKEFILES)/tool.make
mark#Emperor:~/objc-test2$
I really don't get this as /Foundation/NSAttributedString.h clearly contains the interface declaration for NSAttributedString, and NSAttributedString+GNUStepBase.h imports , so any idea on what is going wrong?

Categories in Objective-C aren't working

I'm developing an iOS application that needs to deploy to iOS 3.1.3. I need to extend some of the functionality of the NSData class and am using the following code inside NSData+Base64 (truncated to show the interesting part):
NSData+Base64.h
[...]
#interface NSData (Base64)
+ (NSData *)dataFromBase64String:(NSString *)aString;
- (NSString *)base64EncodedString;
#end
NSData+Base64.m
#implementation NSData (Base64)
[...]
//
// base64EncodedString
//
// Creates an NSString object that contains the base 64 encoding of the
// receiver's data. Lines are broken at 64 characters long.
//
// returns an autoreleased NSString being the base 64 representation of the
// receiver.
//
- (NSString *)base64EncodedString
{
size_t outputLength;
char *outputBuffer =
NewBase64Encode([self bytes], [self length], true, &outputLength);
NSString *result =
[[[NSString alloc]
initWithBytes:outputBuffer
length:outputLength
encoding:NSASCIIStringEncoding]
autorelease];
free(outputBuffer);
return result;
}
#end
However, when I try to message this selector:
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
NSString *hash = [HMAC base64EncodedString];
I get the following error:
-[NSConcreteData base64EncodedString]: unrecognized selector sent to instance 0x6146e70
2010-11-09 13:44:41.443 SpringboardApplication[21318:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteData base64EncodedString]: unrecognized selector sent to instance 0x6146e70'
I read a lot about iOS 3.1.x having problems with categories. I tried adding the flags -all_load and -ObjC (both separately and together) to no avail. I would really appreciate some direction of how to get this selector to work.
Thanks!
It really seems like your category isn't being compiled or linked into the same target that you're using it from. You should make sure that NSData+Base64.m is marked to be compiled by the same target that it's being used from by getting info on the two files and comparing the targets they're assigned to.
A test you can perform is to add a line with an #error error message to NSData+Base64.m, which will cause the build to fail when it gets to that file. Like this:
#error We're now compiling NSData+Base64.m
Then look and see which target fails to compile.
I had the same issue with ARC project which was linking with non-ARC module having category extension.
Fixed the issue by adding "Other Linker Flags: -all_load" in parent ARC project.
Have you #imported the header file for your category? I know it sounds simple, but I forget nearly every time.
There is a great post on The Carbon Emitter about about handling categories in iOS. It details an easy way to handle importing categories to your project.
Make a file containing all of your category imports, in this example it is Extensions.h:
#import "NSDate+Formatting.h"
#import "UIFonts+MyFonts.h"
#import "UIViewController+Tourbot.h"
Add import your file in AppName-Prefix.pch:
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import <CoreText/CoreText.h>
#import "Extensions.h" // Add import here
#endif
In My case when I got this error I simply added the .m file in the Compiled resources, and it get worked. This can be achieved by selecting target project->Build Phases->Compile Sources. Then you click on the + button from its bottom left. In this case you may add 'NSData+Base64.m' file to the compile sources. Then you clean your project and run. I guess this may help.

Error With Foundation.h

I learning Objective-C in Linux(Ubuntu), but when i tryed to compile my application that needs the Foundation headers i got an error saying that the file cannot be found, but i have installed the GNUstep development package(gnustep-devel). Here is my code:
// Fraction.h
#import <Foundation/NSObject.h>
#interface Fraction: NSObject {
int numerator;
int denominator;
}
- (void) print;
- (void) setNumerator: (int) n;
- (void) setDenominator: (int) d;
- (void) numerator;
- (void) denominator;
#end
And here is the console log:
ubuntu#eeepc:~$ gcc main.m -o frac -lobjc
In file included from main.m:3:
Fraction.h:2:26: error: objc/NSObject.h: No such file or directory
In file included from main.m:3:
Fraction.h:4: error: cannot find interface declaration for ‘NSObject’, superclass of ‘Fraction’
ubuntu#eeepc:~$
What i need to do?
how are you compiling it? For me, I create a GNUMakefile makefile for my application (see here), and then I run source /usr/share/GNUstep/Makefiles/GNUstep.sh and then make.
GNUstep Installation Process For Windows
Visit The URL: http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
Download the exe file gnustep-system-0.19.2-setup.exe
Then Download gnustep-core-0.19.2-setup.exe
Remember one thing if you are downloading gnustep-system of any version you must have to download the same version for gnustep-core.
For example if you have downloaded gnustep-setup-0.22.1-setup.exe then you must have to download gustep-core-0.22.1-setup.exe otherwise your code will not run.
Install first the gnustep-system-0.19.2-setup.exe then install gnustep-core-0.19.2setup.exe. Don’t try to install in vice versa order.
Now you got the gnustep for windows then go to start>all program> GNUstep> shell
Now open the notepad editor and write the following code in notepad
#import
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]
init];
NSLog (#"Anil Kumar Yadav has Run the First Objective C
program!");
[pool drain];
return 0;
}
save it as hello.m in your C:/GNUstep/home/foldername
Remember foldername is the name when you first time start the shell it create the envoirment and make a folder by the name of your computer name in C:/GNUstep/home folder. So don’t be panic.Okay
Go to your shell and type the following command gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -constant-string-class=NSConstantString
This command will create a hello.exe file in your foldername folder.
Again in shell type the command ./hello.exe
Finally you will be able to see the output in the shell.
Conguratulation you wrote your first Objective C program successfully.
Need any clarification write me to : ayadav00009#gmail.com
I've searched at the repository and then i installed the foundation lib, now all is working.
Thanks.