Menu
  • HOME
  • TAGS

Linking shared libraries in same directory

Tag: osx,linker,cmake,make,dyld

I'm using CMake to build two shared libraries (.so files). They get built into separate directories, but on the install step they get copies into the same directory. One of them links with the other. And both get loaded dynamically from another process.

The first problem is that apparently CMake does not set an rpath on the .so files on OS X (not tested on other platforms). In CMakeLists.txt I have

set(CMAKE_INSTALL_PREFIX ../dist)
set(MACOSX_RPATH YES)
set(INSTALL_NAME_DIR YES)

And the CMakeLists.txt files for the two libraries get included using

add_subdirectory(./a "${CMAKE_BINARY_DIR}/a")
add_subdirectory(./b "${CMAKE_BINARY_DIR}/b")

But running otool -l on the resulting .so files shows no LC_RPATH entry.

Also, which path would need to be set in the RPath (of a) so that when the linker loads a.so, it can find b.so which is in the same directory (dist/). The executable from which a gets loaded is in a different place.

I've tried @executable_path/, @executable_path/../, @origin/../, but none seem to work.

Best How To :

The first problem is that apparently CMake does not set an rpath

By default cmake does set rpath for target in build directory (see project):

> cmake -H. -B_builds -DBUILD_SHARED_LIBS=ON
> cmake --build _builds
> ls _builds/foo _builds/liba.dylib 
  _builds/foo
  _builds/liba.dylib
> otool -L _builds/foo 
_builds/foo:
  @rpath/liba.dylib (compatibility version 0.0.0, current version 0.0.0)
  ...
> otool -l _builds/foo | grep LC_RPATH -A2
      cmd LC_RPATH
  cmdsize 64
     path /.../_builds (offset 12)

I.e. library will load correctly if you run it from directory _builds:

> ./_builds/foo
a: 42

But running otool -l on the resulting .so files shows no LC_RPATH entry.

Also, which path would need to be set in the RPath

I've tried @executable_path/, @executable_path/../, @origin/../, but none seem to work.

It depends on where you want to install your library and your executable. For instance if destination directories are the same you can set just @executable_path:

set(CMAKE_INSTALL_RPATH "@executable_path")
install(TARGETS foo a DESTINATION bin)

See example project:

> cmake -H. -B_builds -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=_install
> cmake --build _builds --target install
> otool -L _install/bin/foo 
_install/bin/foo:
  @rpath/liba.dylib (compatibility version 0.0.0, current version 0.0.0)
  ...
> otool -l _install/bin/foo | grep LC_RPATH -A2
      cmd LC_RPATH
  cmdsize 32
     path @executable_path (offset 12)

You can test that library will load correctly from _install:

> ./_install/bin/foo
a: 42

Info

  • RPATH Wiki

Mac OSX - Allow for user input in shell script via GUI or Prompt

osx,bash,shell

From what I understand I would recommend you look in to Applescript as this will allow you to have a GUI Interface as well as executing 'SHELL' commands. First of all I would open 'Script Editor' program that comes preinstalled on Mac's This is an example script which asks for...

CGDisplayCopyAllDisplayModes leaves out one valid mode

osx,swift,core-graphics

There's public API that's only documented in the header. CGDisplayCopyAllDisplayModes() takes an options parameter, which is a dictionary. The docs (and even the headers) say that it's unused and you must past NULL, but you can pass a dictionary with the key kCGDisplayShowDuplicateLowResolutionModes and value kCFBooleanTrue. The option name is...

How to display Apple San Francisco's numbers mono-spaced rather than proportionally?

osx,fonts,apple

Number formatting of an OpenType font requires having control over which features are active during text shaping, something which typesetting tools will offer (InDesign, XeLaTeX, etc), but which normal productivity tools still (after a decade of Adobe, Apple, and Microsoft all agreeing on using OpenType!) don't offer. Notes included. So,...

Capitalize all files in a directory using Bash

osx,bash,rename

In Bash 4 you can use parameter expansion directly to capitalize every letter in a word (^^) or just the first letter (^). for f in *; do mv -- "$f" "${f^}" done You can use patterns to form more sophisticated case modifications. But for your specific question, aren't you...

Login with Facebook option trigger suggest to download an app

android,ios,facebook,osx,login

I found out what I was talking about. Facebook is adding a new feature which ask users if they want to get a link to the mobile app. This is in Beta right now but you will automatically eligible for the feature if: You have integrated the new Facebook Login...

How can I fix “Error: Formulae found in multiple taps”?

php,osx,homebrew,phpredis

brew untap josegonzalez/homebrew-php ...

best way to create a mat from a CIImage?

c++,xcode,osx,opencv,opencv3.0

Found a solution to get rid of the crash: use createCGImage:fromRect to skip the NSBitmapImageRef step: - (void)OpenCVdetectSmilesIn:(CIFaceFeature *)faceFeature usingImage:ciFrameImage { CGRect lowerFaceRectFull = faceFeature.bounds; lowerFaceRectFull.size.height *=0.5; CIImage *lowerFaceImageFull = [ciFrameImage imageByCroppingToRect:lowerFaceRectFull]; // Create the context and instruct CoreImage to draw the output image recipe into a CGImage if( self.context...

When listing the contents of /usr/sbin what is the meaning behind color codes of individual programs?

osx,bash

This is a product of using ls --color (you probably have an alias for this; type alias with no args to see what your current ls alias(es) is/are). Use dircolors or echo $LS_COLORS to see system-specific meanings. Here are some examples I copied and pasted from a post on the...

Linker error with variable templates

c++,templates,linker,c++14,template-variables

This is a bug in clang++ #22825. The bug report has been filed on 2015-03-06 and the bug has not yet been fixed. Richard Smith supposes this definition is incorrectly treated only as a forward-declaration.

Set CALayer Gradient Background

objective-c,xcode,osx,cocoa,cocoa-touch

CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.colors = [NSArray arrayWithObjects:(id)[[NSColor whiteColor] CGColor], (id)[[NSColor greenColor] CGColor], nil]; gradient.frame = self.colorView.bounds; [self.colorView setLayer:gradient]; [self.colorView setWantsLayer:YES]; ...

Native Code: cannot use typeid with -fno-rtti

c++,osx,gcc,android-ndk,vtk

To enable C++ in the NDK, add LOCAL_CPP_FEATURES := rtti exceptions and LOCAL_CPPFLAGS += --std=c++11 to the jni/Android.mk file. By default, the NDK supports only a C++-like language. Note that there's no underscore between CPP and FLAGS. Also, I've used += because this won't overwrite other flags such as -Wall....

Change the “about this” window on mac app

java,osx,deployment

If your application is an .app bundle then it should have an info.plist. Inside the info.plist will normally contain version information that should display the version number: <key>CFBundleShortVersionString</key> <string>2.0.0</string> Typically the version information here is populated in places that call for it (eg. About). To change the name that would...

Crash when processing `__Atom` class object in Objective C (using Objective C runtime )

objective-c,osx,objective-c-runtime

+[NSObject isSubclassOfClass:] is a class method for NSObject and not all classes are subclasses of NSObject. It seems as if you have find private class that is not a subclass of NSObject, so it requires a more delicate handling for checking for inheritance. Try: BOOL isSubclass(Class child, Class parent) {...

OSX tmux configuration session open file in vim automatically

osx,session,vim,configuration-files,tmux

Explicitly inserting a space should do it: send -t 1 vim space ~/Path/to/my/file enter or you can quote command arguments (I prefer this one): send -t 1 'vim ~/Path/to/my/file' 'enter' ...

Restrict input on NSTextField

osx,swift,cocoa,nstextfield

You have complete control with a subclass of NSFormatter. I'm not sure why you think you don't. Override isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:) and implement the desired logic. From the docs (with some minor edits by me): In a subclass implementation, evaluate [the string pointed to by *partialStringPtr] according to the context. Return YES...

fatal error: limits.h: No such file or directory

xcode,osx,gcc

Make sure you've installed the xcode command-line tools: xcode-select --install (Accept the pop-up dialog.) That will install system headers into standard locations expected by tools like gcc, e.g. /usr/include....

VS2012 Identifer not found when part of static lib

c,visual-studio-2012,linker,static-libraries

C++ uses something called name mangling when it creates symbol names. It's needed because the symbol names must contain the complete function signature. When you use extern "C" the names will not be mangled, and can be used from other programming languages, like C. You clearly make the shunt library...

ASP.NET vnext overriding status code set in controller. Is this a bug?

osx,asp.net-5,kestrel

The behavior of void returning action was recently changed to not convert to 204 status code. However, for you scenario you could use the CreatedAtRoute helper method(this actually creates a CreatedAtRouteResult) which sets the Location header. [HttpPost] public void Post([FromBody]CrudObject crudObject) { return CreatedAtRoute(routeName: "GetByIdRoute", routeValues: new { id =...

How to get CPU utilization in % in terminal (mac)

osx,terminal,cpu

This works on a Mac (includes the %): ps -A -o %cpu | awk '{s+=$1} END {print s "%"}' To break this down a bit: ps is the process status tool. Most *nix like operating systems support it. There are a few flags we want to pass to it: -A...

Linker error compiling DX10 program in Visual Studio 2015

visual-studio,visual-c++,linker,directx

Which version of the legacy DirectX SDK are you using? Static libraries* from different versions of the Visual C++ compiler are generally not compatible, so my guess is you are using a DirectX SDK that no longer supports VS 2005--I believe the February 2010 DXSDK was the last one that...

Change NSTextField border and BG color while editing

osx,swift,cocoa,nstextfield

You can set the delegate of NSTextField: nameTextField.delegate = self then you can set a different state: func control(control: NSControl, textShouldBeginEditing fieldEditor: NSText) -> Bool { nameTextField.bezeled = true nameTextField.backgroundColor = NSColor.textBackgroundColor() return true } func control(control: NSControl, textShouldEndEditing fieldEditor: NSText) -> Bool { nameTextField.bezeled = false nameTextField.backgroundColor = NSColor.windowBackgroundColor()...

Packaging Kivy Python applications on OSX Yosemite not working

python,osx,kivy,pyinstaller

So even though I don't have my app working still, I've technically answered this question. For whatever reason pyinstaller 2.1 wasn't able to properly find Python or Kivy. When I downloaded pyinstaller 2.0 and ran that, everything built properly. Instead of getting those "Can not find path" errors, I now...

iOS : pod update (unable to find the utility “xcode-select”)

ios,xcode,osx,xcode6,cocoapods

First of all check you have to install command line or not. You can check this by opening Xcode, navigating the menu to Xcode > Preferences > Downloads > Components, finding Command Line Tools and select install/update. if you haven't find command line tool then you need to write this...

Swift Dictionary with Protocol Type as Key

ios,osx,swift,dictionary,protocols

I would probably think in the direction of: protocol SCResourceModel { var hashValue: Int { get } func isEqualTo(another: SCResourceModel) -> Bool // ... } struct SCResourceModelWrapper: Equatable, Hashable { let model: SCResourceModel var hashValue: Int { return model.hashValue ^ "\(model.dynamicType)".hashValue } } func == (lhs: SCResourceModelWrapper, rhs: SCResourceModelWrapper) ->...

How to get NSTableView to use a custom cell view mixed with preset cell views?

osx,swift,cocoa,nstableview,nstableviewcell

I'd try just giving the default cell your own identifier in Interface Builder... ...then just use that in conjunction with makeViewWithIdentifier:: func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView? { var viewIdentifier = "StandardTableCellView" if let column = tableColumn { switch column.identifier { case "nameColumn": viewIdentifier = "nameCellView"...

Using subprocess.check_output for a command with 2>/dev/null

python,osx,subprocess

For 2>/dev/null, the appropriate way to control redirection of file descriptor 2 with the subprocess.Popen family of calls is stderr=: # Python 2.x, or 3.0-3.2 output = subprocess.check_output(['du', '-g', '-d1', '/Users'], stderr=open('/dev/null', 'w')) ...or, with a Python supporting subprocess.DEVNULL: # Python 3.3 or newer output = subprocess.check_output(['du', '-g', '-d1', '/Users'],...

Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)

c++,osx,c++11,compiler-errors,llvm

This line of code is very ambiguous: for (auto it : _unhandledFiles)//ERROR HERE auto uses template argument deduction, so std::string s; std::string& sr = sr; auto x = sr; in the above code x is deduced to be of type std::string, not std::string&. So your loop is equivalent to: for...

MinGW-W64 linker skipping incompatible files when searching for third-party static libraries

c++,windows,linker,g++,mingw-w64

The problem was likely that the libraries were compiled with VC++, so they apparently aren't compatible with GCC. They link fine using Microsoft's link.exe.

Run Boot2Docker from bash

osx,bash,docker,boot2docker

Replace your boot2docker start with boot2docker start && $(boot2docker shellinit) and you are good to go. $(boot2docker shellinit) will export all the Environment variables needed.

What is the meaning of the libstdc++6.dylib version number on mac os x?

osx,g++,macports,libstdc++

If you want to find the corresponding GCC version number for the version of libstdc++, do this: $> port provides /opt/local/lib/libgcc/libstdc++.6.dylib That will tell you which port installed the given file. In my case, that's libgcc, I'll assume it's the same for you. To find out the currently installed version...

Initializing a xib view as a subview of another NSView

objective-c,osx,cocoa,xib,nib

You could use the loadNibNamed:owner:topLevelObjects: method. Here's an example: NSArray *views = nil; [[NSBundle mainBundle] loadNibNamed:@"TestView1" owner:nil topLevelObjects:&views]; [self.view addSubview:[views lastObject]]; The above code will load the top-level contents of the XIB into an array. Per the documentation: Load a nib from this bundle with the specified file name and...

Simulating HID on OSX : IOBluetooth or CoreBluetooth?

ios,osx,core-bluetooth,iobluetooth

CoreBluetooth is for Bluetooth low energy (BLE), whereas IOBluetooth is for classic Bluetooth. iOS devices can connect to HID devices over either transport: the BLE profile is called HOGP: HID over GATT Profile. CoreBluetooth/BLE should be easier to work with, but you'll still need to implement the HID protocol yourself....

How to programatically make a key shortcut?

osx,bash,task-switching

You can use Applescript to achieve this. To focus on a specific application: tell application "Finder" to activate And to emulate an actual Cmd+Tab input: tell application "System Events" key down command keystroke tab key up command end tell Applescript files (*.scpt) can be run through the command line with...

What's the shortcut to interrupt the kernel in Canopy?

osx,kernel,interrupt,shortcut,canopy

There is no shortcut for interrupting the kernel. That command, along with restarting the kernel, is in the Run menu, which also shows the shortcut for the restart kernel command. Note that because of the nature of the interaction between Python and C extensions, neither command is guaranteed to work,...

How do you work with views in MainMenu.xib?

objective-c,xcode,osx,cocoa

So the default is that your main application window is an outlet in the app delegate. You should keep MainMenu.xib's owner as the app delegate. A common alternative, if you are creating your own custom window controller, is to create a property in the AppDelegate of type CustomWindowController, then in...

Read plist inside ~/Library/Preferences/

objective-c,xcode,osx

You need to use NSString method: stringByExpandingTildeInPath to expand the ~ into the full path. NSString *resPath = [@"~/Library/Preferences/" stringByExpandingTildeInPath]; NSLog(@"resPath: %@", resPath); Output: resPath: /Volumes/User/me/Library/Preferences ...

Excel Doc macro yields “Named argument not found (Error 448)”

excel,osx,vba,excel-vba,excel-vba-mac

The Mac does not support the SearchFormat argument. Just omit and the code will run.

pcap_dispatch() always returns 0 on Mac OSX for wifi interface

osx,pcap,libpcap,arp

If you are capturing in monitor mode, you will be getting native 802.11 packets, which do not look like Ethernet packets, so filtering similarly to Ethernet will not work. Furthermore, if you're capturing in monitor mode on a protected network, i.e. a network using WEP or WPA/WPA2, everything past the...

What is the best way to make sure I am not using any unavailable API's on OSX?

objective-c,xcode,osx,cocoa

For the moment, there's no easy way to do this, since as you said, 10.9 is the farthest back you can specify. Until Xcode 7 is released, which I believe will only help with more recent SDKs anyway, you have few choices, none at all convenient: Keep a cheap Mac...

django-admin startproject not working with python3 on OS X

python,django,osx,python-2.7,python-3.x

Recommended: Try using virtualenv and initiate your environment with Python3. Or a quicker solution is to use python interpreter directly to execute django-admin: <path-to-python3>/python /usr/local/bin/django-admin startproject mysite ...

Binding an NSTableView to an array of strings in Swift

osx,swift,cocoa,nstableview,cocoa-bindings

The Class Name should absolutely be set to a valid class. The bigger problem is that the array controller doesn't really play nicely with arrays of strings. There's no (reasonable) way to use -setValue:forKey: on a string since the string is itself what's being edited (replaced), not some property (like...

Cocoa ViewController.m vs. Cocoa Touch ViewController.m

objective-c,osx,cocoa

Before I answered I wanted to check if the same happened to me-- but when I created a custom NSViewController in a new iOS OR OS X app, both would generate the @interface in the implementation file (.m file) So I'm not sure why you are seeing that. However, to...

ffmpeg: wmv files generated on Mac can't be played in Windows

windows,osx,ffmpeg,file-conversion,wmv

You can try a codec for encoding instead. Try this. ffmpeg -i input_gif -b:v 2M -vcodec msmpeg4 -acodec wmav2 output_wmv You may find this important....

C++ basic fileIO locations

c++,osx,file-io

The program tries to find the file you open in the current working directory, not from the location where the executable file is. When you're executing a program from a terminal the current directory is the directory you're in. So if you do e.g. cd ~/ to go to your...

Stuck with creating an event and formatting dates (Swift - EventKit - OS X)

ios,osx,swift,eventkit,ekevent

dateString doesn't match the format you specified. Why not use the built-in short style? This appears to work: let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = .ShortStyle var dateString = "07/16/2015" var startDate = dateFormatter.dateFromString(dateString) var endDate = dateFormatter.dateFromString(dateString) startDate and endDate are optionals, so you'll have to unwrap them. In this...

How to uninstall all python versions and use the default system version of OS X 10.10?

python,osx

The file /usr/bin/python (and /usr/bin/pythonw, which is a hard link to the same file) is actually a launcher program that invokes the default version of Python from /System/Library/Frameworks/Python.framework/Versions. You can select the version (2.6 and 2.7 in Yosemite) the launcher invokes using either the defaults command or the VERSIONER_PYTHON_VERSION environment...

JSON in Python: encoding issue on OS X, no issue on Windows

python,json,windows,osx,encoding

I get your OSX failure on Windows, and it should fail because writing a Unicode string to a file requires an encoding. When you write Unicode strings to a file Python 2 will implicitly convert it to a byte string using the default ascii codec and fails for non-ASCII characters....

Eclipse CDT - No Console Output on OSX

c++,eclipse,osx,terminal,64bit

Are you using the right compiler? If you are compiling with Cross GCC it might not run on a 64bit OS X device. Try using MacOS GCC for compiling if so.

Use Unix Executable File to Run Shell Script and MPKG File

osx,shell,unix

The most common issue when handling variables containing paths of directories and files is the presence of special characters such as spaces. To handle those correctly, you should always quote the variables, using double quotes. Better code would therefor be: sudo sh "$path/join.sh" sudo sh "$path/join2.sh" It is also advised...

Display django runserver output from Vagrant guest VM in host Mac notifications?

python,django,osx,notifications,vagrant

Why not run a SSH server on the VM and connect from the host via a terminal? See MAC SSH. Which OS is running on the VM? It should not be too hard to get the SSH server installed and running. Of course the VM client OS must have an...