Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

rpath problem on OSX #3

Open
nbigaouette opened this issue Jul 9, 2016 · 3 comments
Open

rpath problem on OSX #3

nbigaouette opened this issue Jul 9, 2016 · 3 comments

Comments

@nbigaouette
Copy link
Owner

Compiled example cannot find Qt on OSX due to an rpath issue.

$ cd libqmlbind-sys
$ cargo build --example hello_world
$ otool -L target/debug/examples/hello_world
target/debug/examples/hello_world:
    @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.7.0, current version 5.7.0)
    @rpath/QtNetwork.framework/Versions/5/QtNetwork (compatibility version 5.7.0, current version 5.7.0)
    @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.7.0, current version 5.7.0)
    @rpath/QtQml.framework/Versions/5/QtQml (compatibility version 5.7.0, current version 5.7.0)
    @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.7.0, current version 5.7.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
$ cat target/debug/build/libqmlbind-sys-8282f5495710b036/output
cargo:rustc-flags=-L libqmlbind/qmlbind
cargo:rustc-link-lib=static=qmlbind
Environnement variable 'QT_DIR' not set!
Defaulting to ${HOME}/Qt/${QT_VER}/${QT_COMP} where:
    QT_VER:  5.7
    QT_COMP: clang_64
Using Qt directory: "${HOME}/Qt/5.7/clang_64"
Use QT_DIR environment variable to ovewrite.
cargo:rustc-link-search=framework=${HOME}/Qt/5.7/clang_64/lib
cargo:rustc-link-lib=framework=QtCore
cargo:rustc-link-lib=framework=QtNetwork
cargo:rustc-link-lib=framework=QtGui
cargo:rustc-link-lib=framework=QtQml
cargo:rustc-link-lib=framework=QtWidgets
cargo:rustc-flags=-l stdc++

But then:

$ cargo run --verbose --example hello_world
       Fresh libc v0.2.13
       Fresh libqmlbind-sys v0.0.2 (file:///${HOME}/qmlrsng.git/libqmlbind-sys)
     Running `target/debug/examples/hello_world`
dyld: Library not loaded: @rpath/QtCore.framework/Versions/5/QtCore
  Referenced from: ${HOME}/qmlrsng.git/libqmlbind-sys/target/debug/examples/hello_world
  Reason: image not found
error: Process didn't exit successfully: `target/debug/examples/hello_world` (signal: 5, SIGTRAP: trace/breakpoint trap)

It seems the final binary does not contain LC_RPATH:

$ otool -l target/debug/examples/hello_world | grep LC_RPATH
$ otool -l target/debug/examples/hello_world
target/debug/examples/hello_world:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __PAGEZERO
   vmaddr 0x0000000000000000
   vmsize 0x0000000100000000
  fileoff 0
 filesize 0
  maxprot 0x00000000
 initprot 0x00000000
   nsects 0
    flags 0x0
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 712
  segname __TEXT
   vmaddr 0x0000000100000000
   vmsize 0x0000000000042000
  fileoff 0
 filesize 270336
  maxprot 0x00000007
 initprot 0x00000005
   nsects 8
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x0000000100000f90
      size 0x0000000000036290
    offset 3984
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x0000000100037220
      size 0x0000000000000270
    offset 225824
     align 2^1 (2)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __stub_helper
   segname __TEXT
      addr 0x0000000100037490
      size 0x000000000000040c
    offset 226448
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __gcc_except_tab
   segname __TEXT
      addr 0x000000010003789c
      size 0x00000000000011a0
    offset 227484
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __TEXT
      addr 0x0000000100038a40
      size 0x0000000000002b48
    offset 232000
     align 2^6 (64)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x000000010003b588
      size 0x00000000000019d3
    offset 243080
     align 2^0 (1)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x000000010003cf5c
      size 0x00000000000014b8
    offset 249692
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __eh_frame
   segname __TEXT
      addr 0x000000010003e418
      size 0x0000000000003bd0
    offset 255000
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 872
  segname __DATA
   vmaddr 0x0000000100042000
   vmsize 0x0000000000005000
  fileoff 270336
 filesize 16384
  maxprot 0x00000007
 initprot 0x00000003
   nsects 10
    flags 0x0
Section
  sectname __nl_symbol_ptr
   segname __DATA
      addr 0x0000000100042000
      size 0x0000000000000010
    offset 270336
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 104 (index into indirect symbol table)
 reserved2 0
Section
  sectname __got
   segname __DATA
      addr 0x0000000100042010
      size 0x0000000000000070
    offset 270352
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 106 (index into indirect symbol table)
 reserved2 0
Section
  sectname __la_symbol_ptr
   segname __DATA
      addr 0x0000000100042080
      size 0x0000000000000340
    offset 270464
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000007
 reserved1 120 (index into indirect symbol table)
 reserved2 0
Section
  sectname __mod_init_func
   segname __DATA
      addr 0x00000001000423c0
      size 0x0000000000000010
    offset 271296
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000009
 reserved1 0
 reserved2 0
Section
  sectname __const
   segname __DATA
      addr 0x00000001000423d0
      size 0x0000000000002eb8
    offset 271312
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __thread_vars
   segname __DATA
      addr 0x0000000100045288
      size 0x0000000000000060
    offset 283272
     align 2^0 (1)
    reloff 0
    nreloc 0
     flags 0x00000013
 reserved1 0
 reserved2 0
Section
  sectname __data
   segname __DATA
      addr 0x00000001000452f0
      size 0x0000000000000428
    offset 283376
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __thread_data
   segname __DATA
      addr 0x0000000100045718
      size 0x0000000000000098
    offset 284440
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000011
 reserved1 0
 reserved2 0
Section
  sectname __common
   segname __DATA
      addr 0x00000001000457b0
      size 0x0000000000000a30
    offset 0
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Section
  sectname __bss
   segname __DATA
      addr 0x00000001000461e0
      size 0x0000000000000130
    offset 0
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Load command 3
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x0000000100047000
   vmsize 0x0000000000028000
  fileoff 286720
 filesize 160416
  maxprot 0x00000007
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 4
            cmd LC_DYLD_INFO_ONLY
        cmdsize 48
     rebase_off 286720
    rebase_size 904
       bind_off 287624
      bind_size 1064
  weak_bind_off 288688
 weak_bind_size 264
  lazy_bind_off 288952
 lazy_bind_size 2928
     export_off 291880
    export_size 11664
Load command 5
     cmd LC_SYMTAB
 cmdsize 24
  symoff 304616
   nsyms 3773
  stroff 365880
 strsize 81256
Load command 6
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 3313
     iextdefsym 3313
     nextdefsym 332
      iundefsym 3645
      nundefsym 128
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 364984
  nindirectsyms 224
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 7
          cmd LC_LOAD_DYLINKER
      cmdsize 32
         name /usr/lib/dyld (offset 12)
Load command 8
     cmd LC_UUID
 cmdsize 24
    uuid F518EE43-2023-3094-85CB-9528895A1527
Load command 9
      cmd LC_VERSION_MIN_MACOSX
  cmdsize 16
  version 10.11
      sdk 10.11
Load command 10
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 11
       cmd LC_MAIN
   cmdsize 24
  entryoff 22512
 stacksize 0
Load command 12
          cmd LC_LOAD_DYLIB
      cmdsize 72
         name @rpath/QtCore.framework/Versions/5/QtCore (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 5.7.0
compatibility version 5.7.0
Load command 13
          cmd LC_LOAD_DYLIB
      cmdsize 72
         name @rpath/QtNetwork.framework/Versions/5/QtNetwork (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 5.7.0
compatibility version 5.7.0
Load command 14
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name @rpath/QtGui.framework/Versions/5/QtGui (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 5.7.0
compatibility version 5.7.0
Load command 15
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name @rpath/QtQml.framework/Versions/5/QtQml (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 5.7.0
compatibility version 5.7.0
Load command 16
          cmd LC_LOAD_DYLIB
      cmdsize 72
         name @rpath/QtWidgets.framework/Versions/5/QtWidgets (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 5.7.0
compatibility version 5.7.0
Load command 17
          cmd LC_LOAD_DYLIB
      cmdsize 48
         name /usr/lib/libc++.1.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 120.1.0
compatibility version 1.0.0
Load command 18
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1226.10.1
compatibility version 1.0.0
Load command 19
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 303544
 datasize 1072
Load command 20
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 304616
 datasize 0

A workaround is to replace the @rpath in the binary with absolute paths. For example:

install_name_tool -change @rpath/QtCore.framework/Versions/5/QtCore ${QT_DIR}/lib/QtCore.framework/Versions/5/QtCore target/debug/examples/hello_world

The script libqmlbind-sys/fix_qt_rpath.sh will perform the required change.

@nbigaouette
Copy link
Owner Author

nbigaouette commented Jul 16, 2016

Running the code with

DYLD_FALLBACK_FRAMEWORK_PATH=${QT_DIR}/lib/

seems to fix the issue...

See:

@nbigaouette
Copy link
Owner Author

Seeting DYLD_FRAMEWORK_PATH works also.

@nbigaouette
Copy link
Owner Author

Adding -C link-args=-Wl,-rpath,${QT_DIR}/lib to rustc's argument seems to create a working binary, but there does not seem to be a way to set this flag from build.rs...

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant