1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ローカルのdubプロジェクトに依存するdubプロジェクト

Last updated at Posted at 2016-11-27

自作のライブラリを別のdubプロジェクトにしたかったので調べたけどすぐには見つからなかったので書く。わかれば簡単なことだった。タイトルはこれで適切なんだろうか?

$ tree
.
├── app
│   ├── dub.json
│   └── source
│       └── app.d
└── lib
    ├── dub.json
    └── source
        └── lib.d
lib/source/lib.d
module lib;

import std.stdio;

void func()
{
    writeln("hello!");
}
app/source/app.d
import lib;

void main()
{
    func();//モジュールlibの関数
}
lib/dub.json
{
    "name": "lib",
    "targetType":"library"
}
app/dub.json
{
    "name": "app",
    "dependencies":{
        "lib": "*"
    }
}

このままではlibが見つからないので実行できない。

$ dub run
Selected package lib ~master doesn't exist. Using latest matching version instead.
Root package app references unknown package lib

dub add-local <プロジェクトのディレクトリのパス> してやるとパッケージのリストに追加される。このプロジェクトにだけ……みたいなことは~~できないのかな?~~できる。下に追記

$ dub add-local lib
Registered package: lib (version: ~master)
$ cd app && dub run
Performing "debug" build using dmd for x86_64.
lib ~master: building configuration "library"...
app ~master: building configuration "application"...
Linking...
Running ./app 
hello!

コメントをもらったので追記。dependenciesで指定してやる方法もある。

app/dub.json
{
    "name": "app",
    "dependencies": {
        "lib": {
            "path": "../lib/"
        }
    }
}
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?