'How to link a objective-c library into a c/c++ project
I have this code:
for the objective-c library
GNUmakefile
include $(GNUSTEP_MAKEFILES)/common.make
LIBRARY_NAME = libteste
libteste_OBJC_FILES = ./src/teste.m
libteste_HEADER_FILES_DIR = ./include
libteste_HEADER_FILES_INSTALL_DIR = include
libteste_HEADER_FILES = teste.h
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/library.make
-include GNUmakefile.postamble
teste.h
#import <Foundation/Foundation.h>
@interface SampleClass:NSObject
- (void)sampleMethod;
@end
teste.m
#include "teste.h"
@implementation SampleClass
- (void)sampleMethod {
NSLog(@"Hello, World! \n");
}
@end
for the c source code
Makefile
all: teste
teste: teste.o
g++ -L ../libteste2/obj -o teste -Wl,-rpath='./' teste.o -lone -lteste2
teste.o: teste.c
g++ -I ../libteste2/include -c teste.c -o teste.o
teste.c
#include "teste.h"
int main() {
SampleClass sample;
sample.sampleMethod();
return 0;
}
the objective-c library compiles without errors, but when I try compile the c source code, I got several (because the compiles do not recognize the objective-c code).
Is there any way to link this objective-c library to the c source code?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
