www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - DUB and static libs

reply abad <abad.flt gmail.com> writes:
I have a project which is a mixture of D, C++ and C. I have used 
Make for build automation so far but would like to migrate to DUB.

I have hard time figuring out what to do with C / C++ sections of 
the program. DUB seems to ignore (probably sensibly) everything 
but D source files. I compiled a static library of the non-D 
sections of my program, and now I'd need to tell DUB to include 
the library in the linking stage.

I tried to use "linkerFiles" argument in dub.json but that 
doesn't seem to do anything.

Here's the full dub.json:



{
     "name": "audio_test",
     "description": "audio test.",
     "copyright": "",
     "authors": [""],
     "dependencies": {
	"derelict-imgui": {"version":"~master", "path": 
"./DerelictImgui/"},
	"derelict-glfw3": "~>1.1.0",
	"derelict-gl3": "~>1.0.12",
	"derelict-sdl2": "~>1.9.7",
     },

     "libs": [ "stdc++" ],

     "stringImportPaths": [
         "res"
     ],

     "linkerFiles": [
         "sid.a"
     ]

}

sid.a is the library in question.

Any ideas?
Apr 20 2016
parent reply Mike Parker <aldacron gmail.com> writes:
On Wednesday, 20 April 2016 at 10:19:10 UTC, abad wrote:
 I have a project which is a mixture of D, C++ and C. I have 
 used Make for build automation so far but would like to migrate 
 to DUB.

 I have hard time figuring out what to do with C / C++ sections 
 of the program. DUB seems to ignore (probably sensibly) 
 everything but D source files. I compiled a static library of 
 the non-D sections of my program, and now I'd need to tell DUB 
 to include the library in the linking stage.

 I tried to use "linkerFiles" argument in dub.json but that 
 doesn't seem to do anything.

 Here's the full dub.json:



 {
     "name": "audio_test",
     "description": "audio test.",
     "copyright": "",
     "authors": [""],
     "dependencies": {
 	"derelict-imgui": {"version":"~master", "path": 
 "./DerelictImgui/"},
 	"derelict-glfw3": "~>1.1.0",
 	"derelict-gl3": "~>1.0.12",
 	"derelict-sdl2": "~>1.9.7",
     },

     "libs": [ "stdc++" ],

     "stringImportPaths": [
         "res"
     ],

     "linkerFiles": [
         "sid.a"
     ]

 }

 sid.a is the library in question.

 Any ideas?
"libs": [ "stdc++", "sid.a" ], You'll also need to pass the appropriate linker-specific flag to set the library path in lflags if sid.a isn't already on the path. (dub already supports an importPaths field, but needs a libraryFlags field too given there are at least three different linkers to content with).
Apr 20 2016
parent Mike Parker <aldacron gmail.com> writes:
On Wednesday, 20 April 2016 at 13:12:54 UTC, Mike Parker wrote:

 "libs": [ "stdc++", "sid.a" ],
Oh, if you're using DMD only you can also pass configure it using sourceFiles: "sourceFile": ["/path/to/libsid.a"] The first is the equivalant of: dmd -L-lsid main.d ... And the second: dmd main.d /path/to/libsid.a ...
Apr 20 2016