I have imported the pdf.h file in my view controller class and tried calling
NSString *outPutString = convertPDF(pathToPdfFile);
but while building it gives me linker error:
_convertPDF" refrenced from: -[ScriptViewController searchBarSearchButtonClicked:] in ScriptViewController.o Symbol(s) not found
I have also included libz.dylib in my project.
What am I doing wrong?
Is there any step to be followed before building the project which includes c code?
Also one more question:
Will this search algorithm work on any PDF(simple and formatted pdfs).
What if you change the name of the .m file that calls pdf.h to xxxx.mm ? It's a c++ file.
I tested it and found out it works only with simple ascii pdfs.
Your must use the definition in the pdf.h
#if __cplusplus
extern "C" {
#endif
NSString* convertPDF(NSString * pathToFile);
#if __cplusplus
}
#endif
also in the implementation file *pdf.m*m use:
#if __cplusplus
extern "C" {
#endif
NSString* convertPDF(NSString * pathToFile);
#if __cplusplus
} //Extern C
#endif
Related
I have a function called init in a cpp file, but when I compile it, g++ creates in the object file a symbol named _Z4initv, so when I link after with ld with the option -e init, obviously ld doesn't recognize the symbol init. Is there a way to create symbols name in C style with g++ ?
If you have a definition like e.g.
void init() { ... /* some code */ ... }
Then to inhibit name mangling you need to declare it as extern "C":
extern "C" void init() { ... /* some code */ ... }
If you have a declaration in a header file that you want to include in a C source file you need to check if you're including the header file in a C or C++ source file, using the __cplusplus macro:
#ifdef __cplusplus
extern "C"
#endif
void init(void);
Note that the function in the header file has to be declared with void in the argument list, if it doesn't take any arguments. That's because the declaration void init() means something else in C.
I have the following Problem using doxygen in an C project. I have many internal structures that are not documented. Therefore it set EXTRACT_ALL=NO in my Doxyfile. Unfortunately doxygen still extracts some of them. Here is a minimal working example. Suppose the following header file:
#ifndef HASHTABLE_H
# define HASHTABLE_H
#ifdef __cplusplus
extern "C" {
#endif
typedef void* object;
typedef char *(*object_getname)( object obj);
typedef void (*object_free)( object obj);
typedef mess_int_t (*object_hash)( char *name, mess_int_t size);
typedef struct {
hashtable_entry *next;
object *obj;
} hashtable_entry;
typedef struct {
object_getname name;
object_free freigabe;
object_hash hash;
mess_int_t size;
hashtable_entry **hashtable;
} hashtable_t;
typedef hashtable_t * hashtable;
#ifdef __cplusplus
}
#endif
#endif
and the following options set in the Doxyfile:
EXTRACT_ALL = NO
EXTRACT_PRIVATE = NO
EXTRACT_PACKAGE = NO
EXTRACT_STATIC = NO
EXTRACT_LOCAL_CLASSES = NO
EXTRACT_LOCAL_METHODS = NO
EXTRACT_ANON_NSPACES = NO
But in the generate Data structure list both structures are listed. Some other undocumented structures defined in the same way in other files are not listed as I expect it from the description of EXTRACT_ALL=NO. Why does doxygen extract some and others not?
The whole doxyfile is available at: http://pastebin.com/J7c9BbvW
I am using doxygen 1.8.5
The answer of the problem is, like we already discussed it in the above comments, that the following setup works:
EXPORT_ALL=NO
in the Doxyfile prevents doxygen only extract data structures from header files instead of all source files.
Setting
HIDE_UNDOC_MEMBERS = YES
HIDE_UNDOC_CLASSES = YES
disables the listing of undocumented structures in the header files.
ENABLE_PREPROCESSING = NO
Unfortunately, doxygen does not parse multi-including header files protect:
#ifndef HASHTABLE_H
# define HASHTABLE_H
I have created C function:
header
//FileSystem.h file
#import <Foundation/Foundation.h>
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);
implementation
//FileSystem.mm
#import "FileSystem.h"
#import <sys/xattr.h>
#import <Support/Support.h>
static const char* attrName = "com.apple.MobileBackup";
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url) {
BOOL operationResult = NO;
// some implementation
return operationResult;
}
When i'm calling AddSkipBackupAttributeToItemAtURL from another parts of application everything is OK, except one place where i'm calling function from the block.
__block UpdateFileAsyncOperation* selfOperation = self;
_contentDownloader.completionBlock = ^(NSData* data) {
[data saveForcedToPath:selfOperation.filePath];
NSURL* fileUrlWithScheme = [NSURL fileURLWithPath:selfOperation.filePath];
AddSkipBackupAttributeToItemAtURL(fileUrlWithScheme);
[runLoop removePort:port forMode:NSDefaultRunLoopMode];
[selfOperation completeOperation];
};
In that place ,while linking in progress, there is error:
Undefined symbols for architecture i386:
"AddSkipBackupAttributeToItemAtURL", referenced from:
__36-[UpdateFileAsyncOperation start]_block_invoke in UpdateFileAsyncOperation.o ld: symbol(s) not found for architecture
i386 clang: error: linker command failed with exit code 1 (use -v to
see invocation)
I don't understand why it happens, how it depends on block? and how can I fix that?
Thanks!
Update: it is not dependent on block, i have moved calling of function to another place of class: the error still there. I'm trying to find why
I have solved the problem.
It not dependent on block. It dependent on file extensions.
The problem file was with ".m" extension, other files was with ".mm" extension.
So I have putted next macro in FileSystem.h file
#ifdef __cplusplus
extern "C" {
#endif
BOOL AddSkipBackupAttributeToItemAtURL(NSURL *url);
#ifdef __cplusplus
}
#endif
I've integrated the ZXing QR Code reader library (ZXingWidget) into my iPhone app, but it conflicts with a function from within the CocoaLumberjack logging library that I am also using.
Undefined symbols for architecture i386:
"ExtractFileNameWithoutExtension(char const*, signed char)", referenced from: ...
DDLog.h
NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy);
#define THIS_FILE (ExtractFileNameWithoutExtension(__FILE__, NO))
DDLog.m
NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy) { ...
As I call it in:
DDLogVerbose(#"%#:%#", THIS_FILE, THIS_METHOD);
The cause for this is that whichever Obj-C file contains the headers:
// import QR Code reader APIs
#import "ZXingWidgetController.h"
#import "QRCodeReader.h"
its file extension must be changed from .m to .mm for proper C++ support.
But then I lose my *DDLogVerbose(#"%#:%#", THIS_FILE, THIS_METHOD);* functionality.
What am I missing here to have these two play nice with each other?
If you're including C headers that aren't "C++-ified" into a C++ or Objective C++ file, you need to tell the compiler. Something like
extern "C" {
#include "DDlog.h"
}
in your .mms should work. Alternatively, if DDLog.h is your file, you can do something like
#ifdef __cplusplus
extern "C"
#endif
NSString *ExtractFileNameWithoutExtension(const char *filePath, BOOL copy);
A web search for "extern C" should provide more details/examples.
I have a C++ function which I call from Objective C.I need to pass variables by reference to the C++ function.But I get the following error in xcode - "Expected ';', ',' or ')' before '&' token in foo.h"
Function declaration in "foo.h"
#ifdef __cplusplus
extern "C"
{
#endif
NSString * LLtoUTM(double Lat,double Long,double &UTMNorthing, double &UTMEasting);
#ifdef __cplusplus
}
#endif
Function call in test_viewcontroller.m
double UTM_x;
double UTM_y;
UTMzone = [[NSString alloc] init];
UTMzone = (NSString *) LLtoUTM(latitude,longitude,UTM_y,UTM_x);
Can anyone tell me what is wrong?
Change the file to be test_viewcontroller.mm.
You told it to compile as an Objective-C file, which doesn't understand references. '.mm' means Objective-C++, which can mix the Obj-C and C++ together like what you're attempting to do.
You simply cannot do this in plain Objective-C — because references don't exist in C. They're a C++ feature. So you have to use Objective-C++, which basically means changing your Objective-C files' extensions to ".mm".