Michael Brown
Michael Brown

Reputation: 211

No LC_RPATH's found

I'm using mac os sonoma 14.2.1 and xcode-select is fully updated. I downloaded the .dmg version of SDL2 from the website and put it in /Library/Frameworks.

Heres the code I'm trying to run:

// On linux compile with:
// g++ -std=c++17 main.cpp -o prog -lSDL2

// C++ Standard Libraries
#include <iostream>

// Third-party library
#include <SDL.h>

int main(int argc, char* argv[]){

    if(SDL_Init(SDL_INIT_VIDEO) < 0){
        std::cout << "SDL could not be initialized: " <<
                  SDL_GetError();
    }else{
        std::cout << "SDL video system is ready to go\n";
    }

    return 0;
}

I successfully compiled it with this command:

clang++ main.cpp -I/Library/Frameworks/SDL2.framework/Headers -F/Library/Frameworks -framework SDL2

When I run the a.out file I get this error:

dyld[995]: Library not loaded: @rpath/SDL2.framework/Versions/A/SDL2
  Referenced from: <AE1C0174-AA36-3B1F-A430-56DE38E61E1B> /Users/<myname>/Desktop/sdl_tutorial/source/1_Introduction_to_SDL/a.out
  Reason: no LC_RPATH's found
zsh: abort      ./a.out

I did some research on rpaths but I don't have enough background to fully understand it. Is this some kind of bug in xcode, clang or macOS?

Upvotes: 7

Views: 8733

Answers (3)

Shaoheng Guan
Shaoheng Guan

Reputation: 41

There are two ways to solve the issue,

  1. Use install_name_tool -add_rpath /path/to/shared/lib /path/to/app to tell the app where is the (relative/absolute) shared/lib used during the compiling.

  2. If using CMakeLists.txt to configure and compile the project. i am sure the problem just arises after installing globally. So we need to define INSTALL_RPATH for the install version. After defining the INSTALL_RPATH in CMakeLists.txt, my no LC_RPATH problem is solved.

set_target_properties(
    ${target_name} 
    PROPERTIES 
    INSTALL_RPATH 
    "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_PREFIX}/lib;${CMAKE_SOURCE_DIR}/path/to/shared/lib")  

NOTE: make sure to set the INSTALL_RPATH instead of the CMAKE_INSTALL_RPATH which doesn't work.

Hope this can help you solve the problem.

Upvotes: 3

John Ziegler
John Ziegler

Reputation: 81

I ran into this issue after completing a good number of SFML (.dylib, not framework) projects on an Intel Mac running Mojave. When I migrated my work to a new M3 Mac running Sequoia (and also updated from SFML 2.5.1 to 2.6.1) my project source files would no longer compile, getting almost the exact errors as the OP, including

Library not loaded: @rpath/...

Reason: no LC_RPATH's found

For some reason, I now have to include -rpath /usr/local/lib (or whatever the path is to your .dylib binaries) in my command line options, which in XCode is accomplished by going to Build Settings->Linking-General->Runpath Search Paths, and adding the appropriate path.

Upvotes: 2

A Kiwi
A Kiwi

Reputation: 1

You should be including <SDL2/SDL.h> not <SDL.h>, then you won't need -I/Library/Frameworks/SDL2.framework/Headers

When I upgraded to Ventura, I found that programs that had previously worked started to fail with dyld[...]: Symbol not found: _SDL_AllocFormat. otool -L a.out showed

    @rpath/SDL2.framework/Versions/A/SDL2 (compatibility version 3001.0.0, current version 3001.2.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)

which was as expected, however otool -l a.out | grep -i rpath showed

         name @rpath/SDL2.framework/Versions/A/SDL2 (offset 24)

with no LC_RPATH entry - which is what you're seeing as well, albeit with Sonoma's better error message. So, one fix to this is to add -rpath /Library/Frameworks to your link step (or compile/link step, in your case).

I think it is a mistake not to automatically add the LC_RPATH spec to code that relied on -F/-framework, but not my call.

Upvotes: 0

Related Questions