Closed metadeus closed 11 years ago
I don't have a linux box to help debug. But it is likely because you didn't build llvm-racket.so. Running build.rkt should do that. But it hasn't been updated recently on linux.
I built llvm-racket.so, but build.rkt don't work for me (clang can't build llvm). I've built llvm-racket.so using g++.
I got a linux vm up and running, to help test this. The issue with clang not building it is an issue with clang itself. http://lists.cs.uiuc.edu/pipermail/llvmbugs/2012-March/022344.html
Is it working once you compile with g++?
llvm$ uname -a Linux inex-1022 3.2.0-35-generic #55-Ubuntu SMP Wed Dec 5 17:42:16 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux llvm$ rm llvm-racket.so llvm$ g++ -DSTDC_LIMIT_MACROS -DSTDC_CONSTANT_MACROS -I/usr/lib/llvm-3.1/include/ -shared llvm-racket.cpp -fPIC -o llvm-racket.so llvm$ stat llvm-racket.so Файл: «llvm-racket.so» Размер: 47309 Блоков: 96 Блок В/В: 4096 обычный файл Устройство: 801h/2049d Inode: 13501187 Ссылки: 1 Доступ: (0775/-rwxrwxr-x) Uid: ( 1000/ ashein) Gid: ( 1000/ ashein) Доступ: 2012-12-29 11:29:51.033780642 +0400 Модифицирован: 2012-12-29 11:29:51.033780642 +0400 Изменён: 2012-12-29 11:29:51.033780642 +0400 Создан: - llvm$ cat llvm-test.rkt
(require "unsafe.rkt") llvm$ drracket <Ctrl-O> llvm-test.rkt <Ctrl-R> ffi-lib: couldn't open "/home/ashein/Dropbox/projects/Racket/Aerylisp/llvm/private/ffi/../../llvm-racket.so" (/home/ashein/Dropbox/projects/Racket/Aerylisp/llvm/private/ffi/../../llvm-racket.so: undefined symbol: _ZN4llvm16CallGraphLinkVarE)
I'am new at Racket, so maybe I don't understand something.
I made some fixes which hopefully should have gotten rid of that error, can you try pulling them?
If clang is still giving you issues, just change build.rkt instead of compiling it by hand because there are lots of flags set there that are important.
I rebuilt llvm-racket.so with build.rkt (changed clang to g++) and tried again. Dr.Racket gets a very long time to execute script:
(require "llvm/unsafe.rkt")
(+ 1 2) but result is the same: ffi-lib: couldn't open "/home/ashein/Dropbox/projects/Racket/Aerylisp/llvm/private/ffi/../../llvm-racket.so" (/home/ashein/Dropbox/projects/Racket/Aerylisp/llvm/private/ffi/../../llvm-racket.so: undefined symbol: _ZN4llvm16CallGraphLinkVarE)
The slowness is compiling the racket files. Use raco make
I'm not sure why you are getting the issue still. The error was that libLLVM-3.1 wasn't being linked in on linux and now it is (as I moved that flag to happen in both oses). Are you sure that you didn't somehow get the old .so file. I noticed you are working in a Dropbox folder, and so maybe it synced an old version.
Outside of Dropbox folder, same result.
ashein@inex-1022:~/Dropbox/projects/Racket/Aerylisp$ cd ~/llvm-test/ ashein@inex-1022:~/llvm-test$ ls llvm llvm-test.rkt ashein@inex-1022:~/llvm-test$ cd llvm ashein@inex-1022:~/llvm-test/llvm$ ls build.rkt compiled info.rkt llvm-racket.so llvm-test.rkt~ safe.rkt TODO build.rkt~ examples llvm-racket.cpp llvm.scrbl private simple.rkt unsafe.rkt ashein@inex-1022:~/llvm-test/llvm$ rm llvm-racket.so ashein@inex-1022:~/llvm-test/llvm$ ls build.rkt compiled info.rkt llvm.scrbl private simple.rkt unsafe.rkt build.rkt~ examples llvm-racket.cpp llvm-test.rkt~ safe.rkt TODO ashein@inex-1022:~/llvm-test/llvm$ cat build.rkt
(require srfi/13)
(define (build) (define launcher "/usr/bin/env") (define compiler '("g++")) (define os (system-type 'os)) (match-define (list version) (llvm-config "--version"))
(define shared-library-flags (case os ((unix) '("-shared")) ((macosx) `("-dynamiclib" "-lstdc++"))))
(define llvm-library-flags (list (format "-lLLVM-~a" version) ))
(define architecture-flags (case os ((unix) empty) ((macosx) empty))) (define output-redirection-flags `("-o" ,(case os ((unix) "llvm-racket.so") ((macosx) "llvm-racket.dylib")))) (define cxx-flags (llvm-config "--cxxflags")) (define ld-flags (llvm-config "--ldflags"))
(define source-file '("llvm-racket.cpp")) (define arguments (append compiler shared-library-flags llvm-library-flags architecture-flags output-redirection-flags cxx-flags ld-flags source-file))
(let-values (((process out in err) (apply subprocess #f #f (current-error-port) launcher arguments))) (close-output-port in) (close-input-port out) (subprocess-wait process) (unless (= (subprocess-status process) 0) (error 'c-compiler "Returned non zero exit code"))))
(define (llvm-config flags) (define (remove-blanks lst) (filter (lambda (x) (not (equal? x ""))) lst)) (remove-blanks (regexp-split " " (let-values (((process out in err) (subprocess #f #f #f "/usr/bin/env" "llvm-config" flags))) (begin0 (string-trim-both (port->string out)) (close-output-port in) (close-input-port err) (close-input-port out) (subprocess-wait process) (unless (= (subprocess-status process) 0) (error 'llvm-config "Returned non zero exit code for flags: ~a" flags)))))))
(build) ;rsync -r . ~/proj/racket/planet/llvm/1.0
ashein@inex-1022:~/llvm-test/llvm$ racket build.rkt ashein@inex-1022:~/llvm-test/llvm$ llvm-config --version 3.1 ashein@inex-1022:~/llvm-test/llvm$ ls build.rkt compiled info.rkt llvm-racket.so llvm-test.rkt~ safe.rkt TODO build.rkt~ examples llvm-racket.cpp llvm.scrbl private simple.rkt unsafe.rkt ashein@inex-1022:~/llvm-test/llvm$ cd .. ashein@inex-1022:~/llvm-test$ ls llvm llvm-test.rkt ashein@inex-1022:~/llvm-test$ drracket
It works for me, on a clean download. I'm not sure what your issue is, but I am not able to debug it, Sorry.
Bug traced. It turns out that if you use the standard library linker, then the resulting ffi library needs to be loaded with the #:global? #t option. I remember seeing this because Jon Rafkind ran into similar FFI issues with the allegro graphical bindings.
I've modified my branch for llvm-3.3 https://github.com/dyoo/racket-llvm/tree/llvm-3.3 so that it does this. I also modified build.rkt so it drives the build process with dynext/compiler and dynext/link.
Now it works! Thanks.
Code:
lang racket
(require "llvm/unsafe.rkt")
Result: ffi-lib: couldn't open "/home/<...>/llvm/private/ffi/../../llvm-racket.so" (/home/<...>/llvm/private/ffi/../../llvm-racket.so: undefined symbol: _ZN4llvm16CallGraphLinkVarE)
System: Ubuntu 12.04 amd64 LLVM-3.1