www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DUB and pragma lib - OSX

reply Joel <joelcnz gmail.com> writes:
How do I get this C stuff working with DUB? I tried putting the 
pragmas in the main source file.

extern(C) char* readline(const(char)* prompt);
extern(C) void add_history(const(char)* prompt);

pragma(lib, "readline");
pragma(lib, "curses");

Linking...
Undefined symbols for architecture x86_64:
   "_add_history", referenced from:
       _D5mmisc7getLineFAyaZAya in bookkeeping.o
   "_readline", referenced from:
       _D5mmisc7getLineFAyaZAya in bookkeeping.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to 
see invocation)
--- errorlevel 1
dmd failed with exit code 1.
Joels-MacBook-Pro:BookKeeping joelcnz$

The C stuff works without DUB.
Apr 19 2016
next sibling parent Edwin van Leeuwen <edder tkwsping.nl> writes:
On Wednesday, 20 April 2016 at 05:53:28 UTC, Joel wrote:
 How do I get this C stuff working with DUB?
Mind posting your dub configuration file?
Apr 19 2016
prev sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 20/04/2016 5:53 PM, Joel wrote:
 How do I get this C stuff working with DUB? I tried putting the pragmas
 in the main source file.

 extern(C) char* readline(const(char)* prompt);
 extern(C) void add_history(const(char)* prompt);

 pragma(lib, "readline");
 pragma(lib, "curses");

 Linking...
 Undefined symbols for architecture x86_64:
    "_add_history", referenced from:
        _D5mmisc7getLineFAyaZAya in bookkeeping.o
    "_readline", referenced from:
        _D5mmisc7getLineFAyaZAya in bookkeeping.o
 ld: symbol(s) not found for architecture x86_64
 clang: error: linker command failed with exit code 1 (use -v to see
 invocation)
 --- errorlevel 1
 dmd failed with exit code 1.
 Joels-MacBook-Pro:BookKeeping joelcnz$

 The C stuff works without DUB.
Dub does separate compilation and linking. Add them as "libs": ["readline", "curses"] for dub.json (sdl is a bit similar).
Apr 19 2016
parent Joel <joelcnz gmail.com> writes:
On Wednesday, 20 April 2016 at 06:16:35 UTC, rikki cattermole 
wrote:
 On 20/04/2016 5:53 PM, Joel wrote:
 [...]
Dub does separate compilation and linking. Add them as "libs": ["readline", "curses"] for dub.json (sdl is a bit similar).
Yay! Worked, thanks rikki cattermole!
Apr 19 2016