How do I import a package from the local filesystem using dub? - d

I have a project that uses dub. I want to use an external file vendored into my project, as a dependency. How do I do this? I don't want to have it in my project's source/ dir. I don't want to add it as a dub managed dependency, but I do want to be able to just import xxx.
The package is this one: https://github.com/gianm/d-json , it does not use dub or have a dub.json project file.

Alternative thing: make a third_party directory, put the file in there, then add that to the sourcePaths in your dub config (you'll probably specify both ["third_party", "source"] since the default source will be overridden if you don't list it too.

Convert the package to dub by adding a dub.json file in the root, with the following contents: {"name": "jsonx"}. Create a source folder, and move jsonx.d into it.
Put the folder anywhere you want, e.g. top-level next to your own project.
Add the following dependency to your dub.json:
"dependencies": {
...
"jsonx": {"path": "../jsonx/"}
}
You can now import the package anywhere using import jsonx;.
In conclusion, if your app is in a dir called app, your tree should look like this:
.
├── app
│   ├── dub.json
│   └── source
│      └── myapp.d
└── jsonx
├── dub.json
└── source
└── jsonx.d

Related

Googletest no such file or directory

I want to import my c++ code in the testing file i'm using for unittesting, but googletest can't find it. When i try to import on another file on same folder level it works.
BUILD: https://pastebin.com/UR048jg4
WORKSPACE: https://pastebin.com/cZ4KuN4t
I'm trying to import my file like this
#include "myvector.h"
├── BUILD
├── hello_test.cc
├── main.cpp
├── myvector.cpp
├── myvector.h
└── WORKSPACE
EDIT:
I don't know why, but i can't answer to comments. Thanks a lot to everyone
the problem was that i wasn't including myvector.h in my srcs in the BUILD file
I managed to get it working, i wasn't including myvector.h in my bazel BUILD file. This is the correct file
cc_test(
name = "hello_test",
size = "small",
srcs = ["hello_test.cc", "myvector.h"],
deps = ["#com_google_googletest//:gtest_main"],
)

Can I have source code ouside project folder in xcode?

I just created my first xcode C++ project. Directory structure looks like the following:
myproject
+-xproject
+-xproject
| +-main.cpp
+-xproject.xcodeproj
Let me describe it (not sure if its necessary). The base folder is myproject, everything inside it was created by xcode.
Instead, I would like have main.cpp outside, like the following:
myproject
+-main.cpp
+-xproject
+-xproject.xcodeproj
Is that possible? How can I get things this way?
Why I want that? Because different IDEs offer different benefits (and debugging in qtcreator might be less straightforward than in xcode, How to debug C++ project using Qt Creator?)
Actually xproject.xcodeproj is a folder which contains:
xproject/xproject.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│   ├── contents.xcworkspacedata
│   ├── xcshareddata
│   │   └── IDEWorkspaceChecks.plist
│   └── xcuserdata
│   └── user.xcuserdatad
│   └── UserInterfaceState.xcuserstate
└── xcuserdata
└── user.xcuserdatad
└── xcschemes
└── xcschememanagement.plist
What I tried (looks like Eljay approach): Open project on xcode, remove xproject/main.cpp and then add myproject/main.cpp. Hit play button and it says build succedded. But also says:
Could not launch "xproject"
LLDB provided no error string.
When I click details I get:
Domain: IDEDebugSessionErrorDomain
Code: 3
Failure Reason: LLDB provided no error string.
User Info: {
DVTRadarComponentKey = 855031;
RawLLDBErrorMessage = "LLDB provided no error string.";
}
ln -s xproject/main.cpp main.cpp
Although I don't like this solution because the original file have to be inside xcode project.
I tried the oposite, but then xcode refuses to work.

Reason to add empty source file to a STATIC library?

I've seen this quite a lot in C++, that developers add an empty source file to the library in CMake. One example is here, with the empty source file found here.
The CMake file has this line:
# build the library
add_library(${PROJECT_NAME} STATIC src/dependency-tracker.cc)
This is only the case if there are no other source files in the src folder, so the library would be 'header only'. Why do they do this?
The directory structure i was referring to:
.
├── CMakeLists.txt
├── include
│   └── okvis
│   └── kinematics
│   ├── implementation
│   │   └── Transformation.hpp <- header only implementation
│   ├── operators.hpp
│   └── Transformation.hpp
├── src
│   └── dependency-tracker.cc <- empty source file
└── test
├── runTests.cpp
└── TestTransformation.cpp
The project specifies CMake 2.8.11 as a minimal requirement:
cmake_minimum_required(VERSION 2.8.11)
This version lacks for INTERFACE library type, which nowadays is a standard representation of a header-only library. (Support for INTERFACE libraries firstly appeared in CMake 3.0).
Without INTERFACE library available, a normal library with a single empty source file looks like a good alternative.
I don't know why dependency-tracker.cc name choosen for the empty source file. Probably, this name has some special meaning for the project's developers.

Sublime Linter with clang can't find header file in header

I'm using sublime text with the sublime linter plugin especially with clang.
When I open a folder, it use the root of the folder as a header location, so if I have
src
├── World
│   ├── Chunk.cpp
│   ├── Chunk.hpp
│   ├── World.cpp
│   └── World.hpp
└── main.cpp
In World.cpp I need to include "World/World.hpp".
But if in World.hpp I include Chunk.hpp the same way ("World/Chunk.hpp"), I get an error but
in World.hpp I have no error. Error are only in file I include that include other file.
I had the same issue. You need to tell clang where to look for the files, i.e. which directories you want to include. Go Preferences --> Package Settings --> SublimeLinter --> Settings and add a new section for clang++:
// SublimeLinter Settings - User
{
"linters":
{
"clang++": {
"I" : [
"${folder}/src",
"${file_path}",
]
}
}
}
In your case the two include directories will actually point to the same path but in general, the first version is to include your source directory (e.g. you have a unit test from a different folder open which accesses code from you src directory) and the second line includes the location of your current file.
If you need different directories, find some more variables you can use here.

gitignore pattern to include all directories with a specific sub directory

I am trying to setup a .gitignore file for openFrameworks. I have a folder that contain project folders - each one has a src directory. I would like to include the folder itself and the src directory only for every project.
Here is my current .gitignore file
# ignore these files
# ignoring everything except spec items
*
# allow these files
!.gitignore
!/README.md
!/*/src
Any help would be greatly appreciated. Ideally I would like the committed folder structure to look something like this:
.
├── project_1
│   └── src
│   └── file.cpp
├── project_2
│   └── src
│   └── file.cpp
└── project_3
└── src
└── file.cpp
What am I missing? Thank you.
If you ignore files and folders (with '*'), you won't be able to exclude sub-folders.
The rule to remember remains:
It is not possible to re-include a file if a parent directory of that file is excluded.
Try instead ignoring files only.
**
Then you can exclude subfolders like src:
!.gitignore
!/README.md
!src/
# or, to be more specific
!/*/src
For any element that would be still ignored, check what rule is involved with:
git check-ignore -v -- an/ignored/element