objective-c smb volume mount fsmountservervolumesync - xcode

I trying to mount the volume programmatically with code I found here
I getting this error while compiling it.
Ld /Users/alex/Library/Developer/Xcode/DerivedData/SambaTestApp-bthesiirajzqwebkatfdkbgalpwc/Build/Products/Debug/SambaTestApp normal x86_64
cd "/Users/alex/Documents/Xcode Projects/SambaTestApp"
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/alex/Library/Developer/Xcode/DerivedData/SambaTestApp-bthesiirajzqwebkatfdkbgalpwc/Build/Products/Debug -F/Users/alex/Library/Developer/Xcode/DerivedData/SambaTestApp-bthesiirajzqwebkatfdkbgalpwc/Build/Products/Debug -filelist /Users/alex/Library/Developer/Xcode/DerivedData/SambaTestApp-bthesiirajzqwebkatfdkbgalpwc/Build/Intermediates/SambaTestApp.build/Debug/SambaTestApp.build/Objects-normal/x86_64/SambaTestApp.LinkFileList -mmacosx-version-min=10.7 -fobjc-arc -framework Foundation -o /Users/alex/Library/Developer/Xcode/DerivedData/SambaTestApp-bthesiirajzqwebkatfdkbgalpwc/Build/Products/Debug/SambaTestApp
Undefined symbols for architecture x86_64:
"_FSMountServerVolumeSync", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
and my code is:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
#autoreleasepool {
NSString * user = #"user";
NSString * password = #"pass";
NSURL * url = [NSURL URLWithString: #"smb://lemon"];
NSURL * mountDir = [NSURL URLWithString: #"/review"];
OptionBits flags = 0;
OSStatus err = FSMountServerVolumeSync (
(__bridge CFURLRef) url,
(__bridge CFURLRef) mountDir,
(__bridge CFStringRef) user,
(__bridge CFStringRef) password,
NULL,
flags);
if(err != noErr)
NSLog( #"some kind of error in FSMountServerVolumeSync - %d", err );
}
return 0;
}

You need to link against the CoreServices framework.

Related

cgo on macOS - unknown type name NSString

In a go code i have following code:
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -L./ ${SRCDIR}/test.dylib -framework Foundation
#include "./test.h"
#include <stdlib.h>
#include <stdio.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSString.h>
*/
import "C"
test.h has a struct with NSString
On building the go code it shows
error: unknown type name 'NSString' NSString nspath,
can someone guide what's wrong here since i have included appropriate objective C libraries and headers.
Not running OSX/iOS, but looking at github, it looks like at least some developers wrap objective-c code in the cgo preamble inside a typical C function.
This looks like a particularly good example:
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/NSBundle.h>
#import <Foundation/NSString.h>
#include <stdlib.h>
#include <string.h>
const char *assets_zip_path() {
NSString *path = [[NSBundle mainBundle] pathForResource: #"aaaaxy" ofType: #"dat"];
const char *data = [path UTF8String];
if (data == NULL) {
return NULL;
}
return strdup(data);
}
*/
import "C"
func openAssetsZip() (*os.File, error) {
pathCStr := C.assets_zip_path()
...
You also may already find the bindings you need in the go/mobile package.

QtMac::toNSImage Undefined symbols for architecture x86_64

I am trying to use notifications in a Qt application on Mac.
Here is part of my class
#include <Cocoa/Cocoa.h>
#include <QtMacExtras/QtMac>
#include <objc/objc.h>
#include <QString>
#include <QPixmap>
void QgsMacNative::showDesktopNotification( const QString &summary,
const QString &body,
const QgsNative::NotificationSettings &settings )
{
NSUserNotification *notification = [[NSUserNotification alloc] init];
notification.title = summary.toNSString();
notification.informativeText = body.toNSString();
notification.soundName = NSUserNotificationDefaultSoundName; //Will play a default sound
notification.contentImage = QtMac::toNSImage( QPixmap::fromImage( settings.image ) );
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification: notification];
[notification autorelease];
}
Here is the error message I get:
Undefined symbols for architecture x86_64:
"QtMac::toNSImage(QPixmap const&)", referenced from:
QgsMacNative::showDesktopNotification(QString const&, QString const&, QgsNative::NotificationSettings const&) in qgsmacnative.mm.o
ld: symbol(s) not found for architecture x86_64
Any idea what's going on?
Finally found it.
In CMakeLists.txt, I had
FIND_PACKAGE(Qt5MacExtras)
but was missing
TARGET_LINK_LIBRARIES(qgis_native Qt5::MacExtras)
In my case, I was missing QT += entries in my .pro file.
Example:
QT += widgets core gui
Should have been:
QT += widgets core macextras gui

LoadFinished false even for local html file load

We had developed an ".app" installer for MAC OSX using C++ / QT. We were facing issues with loadFinished signal being called with false intermittently even while loading html file which is from local file system.
I found some other posts regarding loadFinished signal being called multiple times. In my case, the signal is called only once with false.
Anyone faced this kind of issue? Relying loadProgress signal with the value 100 is fine?
QT - 4.8.2
Mac OS X - 10.7
Code Snippet:-
boost::scoped_ptr<QWebView> m_webViewP;
static const boost::filesystem::path kJSEntryPoint = boost::filesystem::path("web") / boost::filesystem::path("index.html");
QUrl fileURL(QString::fromStdString(ISettingsManager::getInstance()->getJSEntryPoint()));
Log(INFO, "Loading auth page[%s].", qPrintable(fileURL.toString()));
m_webViewP->load(fileURL);
m_webViewP->activateWindow();
m_webViewP->raise();
const std::string SettingsManagerImpl::getJSEntryPoint() const
{
boost::filesystem::path retPath;
retPath = getAppDir_();
retPath /= kJSEntryPoint;
std::string toRet = retPath.string();
convertToURL_(toRet);
return toRet;
}
void SettingsManagerImpl::convertToURL_(std::string &path) const
{
size_t index = path.find(kBackSlash);
while (index != std::string::npos)
{
path.replace(index, 1, kForwarSlash);
index = path.find(kBackSlash);
}
path = kURLPrefix + path;
}
boost::filesystem::path SettingsManagerImpl::getAppDir_() const
{
#ifdef _WIN32
TCHAR pathName[MAX_PATH];
if (::GetModuleFileName(NULL, pathName, MAX_PATH) == 0)
{
SSLog(ERROR, "Error while retrieving app path.");
return "";
}
::PathRemoveFileSpec(pathName);
return boost::filesystem::path(pathName);
#else
NSAutoreleasePool *poolP = [[NSAutoreleasePool alloc] init];
NSString *pathP = [[NSBundle mainBundle] executablePath];
pathP = [pathP stringByDeletingLastPathComponent];
boost::filesystem::path toRet([pathP cStringUsingEncoding:NSASCIIStringEncoding]);
[poolP drain];
return toRet;
#endif
}

Compilation error when compiled using g++ instead of gcc

I have a function which when compiled using gcc works fine, but when I compile it with g++, it gives me this error:
bon_io.cpp:In function ‘lruc_item* lruc_pop_or_create_item(lruc*)’:
bon_io.cpp:4751: error: invalid conversion from ‘void*’ to ‘lruc_item*’
Code:
typedef struct {
void *value;
void *key;
uint32_t value_length;
uint32_t key_length;
uint64_t access_count;
void *next;
} lruc_item;
lruc_item* lruc_pop_or_create_item(lruc *cache1)
{
lruc_item *item = NULL;
if(cache1->free_items) {
item = cache1->free_items;
cache1->free_items = item->next; [LINE 4751]
} else {
item = (lruc_item *) calloc(sizeof(lruc_item), 1);
}
return item;
}
I am trying to use this function with a c++ code, that's why need to compile it with g++, it works fine if I compile it using gcc but not with g++.
Can anyone please suggest me a way out to make this work with g++ ?
Thanks
How about:
cache1->free_items = (lruc_item *) item->next;
but then why is it that it gets compiled perfectly using gcc and gives
me error with g++
Because in C++ you can't automatically convert from void * to another pointer type.

What is the exact equivalent to LD_PRELOAD on OSX?

I am using LD_PRELOAD to hook a library function, and in Linux it works perfectly. But I cannot figure out how to do the equivalent in OSX.
The setup I have on Linux is as follows:
The code is:
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <unistd.h>
#include <ruby.h>
void
rb_raise(unsigned long exc, const char *fmt, ...)
{
static void (*libruby_rb_raise)
(unsigned long exc, const char *fmt, ...) = NULL;
void * handle;
char * error;
if (!libruby_rb_raise) {
handle = dlopen("/path/to/libruby.so",
RTLD_LAZY);
if (!handle) {
fputs(dlerror(), stderr);
exit(1);
}
libruby_rb_raise = dlsym(handle, "rb_raise");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
}
}
// ...code...
return Qnil;
}
Which I then compile with:
gcc -Wall -O2 -fpic -shared -ldl -g -I/path/to/includes/ -o raise_shim.so raise_shim.c
I then execute with:
LD_PRELOAD=./raise_shim.so ruby
All of the above works well on Linux, what is the equivalent for each step to get this working on OSX? I have googled this and have not been able to get it to work with the information provided as the info for some of the steps are missing.
Thanks in advance!
Take a look at DYLD_INSERT_LIBRARIES. That's the variable you're looking for.
See also this answer.

Resources