This might be stupidiest and newbie's question, but how do I actually compile D project with DMD on windows?
I tried these commands:
dmd *
dmd *.d
cd .. && dmd {DirectoryName}
dmd file1.d file2.d
But neither of them compile the project to executable.
I want to produce .exe file out of that project, but it seems I can't. I can only compile one file in the project or compile multiple, but only .obj file, not .exe...
DUB is the easiest for beginners:
C:\Users\217216x715132\Desktop\tmp1>dub init
Package recipe format (sdl/json) [json]:
Name [tmp1]:
Description [A minimal D application.]:
Author name [217216X715132]:
License [proprietary]:
Copyright string [Copyright © 2019, 217216X715132]:
Add dependency (leave empty to skip) []:
Successfully created an empty project in 'C:\Users\217216x715132\Desktop\tmp1'.
Package successfully created in .
C:\Users\217216x715132\Desktop\tmp1>dub run
Performing "debug" build using dmd for x86.
tmp1 ~master: building configuration "application"...
Linking...
Running .\tmp1.exe
Edit source/app.d to start your project.
C:\Users\217216x715132\Desktop\tmp1>
You can copy all your d files to your-project\source\ directory and let dub do all the hard work.
dub init doesn't work from git bash for some reason, as it waits for input on CLI. So you need to dub init from cmd.exe. dub run should work fine from git bash.
If you run it from git bash, press enter key 7 times, all the defaults will be accepted and the project will be created.
arun MINGW64 ~/Desktop/tmp1$ dub init
Package recipe format (sdl/json) [json]: Name [tmp1]: Description [A minimal D application.]: Author name [217216X715132]: License [proprietary]: Copyright string [Copyright © 2019, 217216X715132]: Add dependency (leave empty to skip) []: Successfully created an empty project in 'C:\Users\217216x715132\Desktop\tmp1'.
Package successfully created in .
arun MINGW64 ~/Desktop/tmp1$
Related issue in DUB
If you don't like Dub, you might try rdmd, which comes with the standard D compiler. E.g suppose you have a main.d file that imports other files:
rdmd --build-only main.d # Build
rdmd --build-only -g -debug main.d # Build in debug mode
rdmd main.d # Build temporary executable and run it
If you want to see the raw commands that dub executes to build your project, you can use:
dub build --force --verbose
Related
I'm installing dependencies for some project which downloads dependencies with vcpkg (the project is Hyperledger Iroha, but it does not matter). Unfortunately when compiling dependencies with my compiler (g++ 12.1.0) one of packages (abseil) is not compiling.
The reason why it is not compiling is easy to fix in code - just one line to change.
The line is pointed by cmake:
CMake Error at scripts/cmake/vcpkg_execute_build_process.cmake:146 (message):
Command failed: /usr/bin/cmake --build . --config Debug --target install -- -v -j13
Working Directory: /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/x64-linux-dbg
See logs for more information:
/home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/install-x64-linux-dbg-out.log
and the error is:
/home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/buildtrees/abseil/src/ca9688e9f6-e4cda1d679.clean/absl/debugging/failure_signal_handler.cc:139:32: error: no matching function for call to ‘max(long int, int)’
139 | size_t stack_size = (std::max(SIGSTKSZ, 65536) + page_mask) & ~page_mask;
| ~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/12.1.0/algorithm:60,
The reason is easy to fix - I just need to change one line to fix this.
Unfortunately when I'm changing the line of code and then after rerunning:
vcpkg install abseil
my changes are being removed before compilation. I found option which should help:
--editable, but it is happening again.
I would like to ask what is more professional (but still fast) way to change files, which are being build with vcpkg and containing errors?
The one solution which I found is that I can edit package:
-- Using cached /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/downloads/abseil-abseil-cpp-997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz
when I edit the package I see error:
File path: [ /home/agh/Pulpit/blockchain/internship2022/iroha/vcpkg-build/downloads/abseil-abseil-cpp-997aaf3a28308eba1b9156aa35ab7bca9688e9f6.tar.gz ]
Expected hash: [ bdd80a2278eef121e8837791fdebca06e87bfff4adc438c123e0ce11efc42a8bd461edcbbe18c0eee05be2cd6100f9acf8eab3db58ac73322b5852e6ffe7c85b ]
Actual hash: [ cf8bb1676d2fcba8bdd4bc30e2060bc5552a348d6e192561aec2763460120b10dcb86e29efe60d972d4b241783563bc8067381c48209daee4ecc429786ef6bba ]
so I can edit file containing the hash: ports/abseil/portfile.cmake
Another solution is to run proper cmake of the abseil project with VERBOSE=1, then copy failing build commands after that edit files and rerun commands.
I know that my solutions are quite dirty so I would like to know if there is cleaner way to solve problem - how to edit source code of a library when it is not compiling when we use vcpkg package manager?
This is how I do it:
Run install with --editable
vcpkg install abseil --editable
Initialize git repo in source dir:
cd buildtrees/abseil/src/_random_string_/
git init .
git add .
git commit -m "init"
Patch the library
Verify the library builds by calling install with --editable again
vcpkg install abseil --editable
Create patch from changes (or commits)
git diff > fix_build.patch
Copy patch into port dir and adjust portfile.cmake
vcpkg_from_github(
REPO google/abseil
...
PATCHES fix_build.patch # <-- this is our patch
)
Copy the port directory into your project's overlay-ports dir. -OR- Update port version, submit it into your custom registry.
(optional, but appreciated) Create PR in upstream and vcpkg main repo.
I'm trying to install boost to run PyGMO properly. However, after I unpack it in a directory (did not use git).
After running bootstrap vc142 (I'm using VScode V1.63.2 and I'm on windows). I'm getting this error:
Building Boost.Build engine
LOCALAPPDATA=C:\Users\wojci\AppData\Local
could not find "vswhere"
Call_If_Exists "..\bin\VCVARS32.BAT"
###
### Using 'msvc' toolset.
###
Followed by:
C:\Program Files\boost\boost_1_78_0\tools\build\src\engine>dir *.exe
Volume in drive C has no label.
C:\Program Files\boost\boost_1_78_0\tools\build\src\engine>copy /b .\b2.exe .\bjam.exe
The system cannot find the file specified.
Failed to build Boost.Build engine.
Does anyone know how to fix/work around this?
Thank you in advance
I found the solution here (git)
Prerequisites:
First download and install MinGW installer mingw-w64-install.exe (I fot it from Sourceforge) and make sure you use x86_64 architecture.
Then download the boost file (boost_1_78_0.zip source)
Open and run cmd as admin
Enter the following command to link the MinFW folder in C:\
mklink /J C:\MinGW "C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64"
add MinGW to the system PATH:
set PATH=%PATH%;C:\MinGW\bin
setx /M PATH "%PATH%"
Check if you have at least g++ version of 8.1.0
g++ --version
Methodology to install boost:
Navigate to the install folder created and unzip and extract the boost_1_78_0.zip file into this folder
In the CMD navigated to the boost folder
cd C:\install\boost_1_78_0
Type the following to make directories for building and installing boost
mkdir C:\boost-build
mkdir C:\install\boost_1_78_0\boost-build
mkdir C:\boost
Setup boost.build (second line prepers b2, the third line builds boost.build with b2, and the fourth line adds C:\boost-build\bin to your session PATH variable)
cd C:\install\boost_1_78_0\tools\build
bootstrap.bat gcc
b2 --prefix="C:\boost-build" install
set PATH=%PATH%;C:\boost-build\bin
building boost (first line navigateds to boost directory, second line builds boost with b2 this can take a while)
cd C:\install\boost_1_78_0
b2 --build-dir="C:\install\boost_1_78_0\build" --build-type=complete --prefix="C:\boost" toolset=gcc install
Extra notes:
This should work for boost 1.68.0 too and might work for other version just replace 1_78_0 with 1_68_0.
At the end you should have three lines that look something like this:
...failed updating 72 targets...
...skipped 292 targets...
...updated 22164 targets...
It's totally fine if you have some failed and skipped files.
Type "native tools " in the start search.
Run "Native tools for visual studio" as an administrator. A command prompt opens.
change directory to boost .
run command "bootstrap".
Follow up by ".\b2".
Wait for a while.
Worked for me. Hope it helps.
I have made new file 'Makefile.local' and add "WINDOWS_SCIP_DIR=c:/Program Files/SCIPOptSuite" to the file.
SCIP is also compiled and the file path is correct.
We have recently updated the installation instructions here:
https://developers.google.com/optimization/install/cpp/source_windows
Can you check them against what you did?
Thanks
You must use a path without space since Makefile can't support it everywhere on a windows prompt (e.g. wildcard function in Makefile inside a if command).
if you have installed SCIP using the SCIPOptSuite 6.0.2 64bits Windows installer it should be located in %ProgramFiles%\SCIPOptSuite 6.0.2 first you need to find the short name version for each directories
dir "%ProgramFiles%*" /x
...
Directory of C:\
01/06/2020 10:35 AM <DIR> PROGRA~1 Program Files
dir "%ProgramFiles%\SCIP*" /x
...
01/06/2020 10:35 AM <DIR> SCIPOP~1.2 SCIPOptSuite 6.0.2
so in my case I can use:
set WINDOWS_SCIP_DIR=C:\PROGRA~1\SCIPOP~1.2
then you can check using:
cd <path_to_your_ortools_source_install>
set PATH=%PATH%;tools;tools\win
make check_third_party
to test you can run the sample examples/integer_programming.cc using:
make rcc_integer_programming
I am doing this Tutorial
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
But I got confused. I stopped at building the OpenCV from source.
I already created an File called Workspace where I made the cmake_binary_dir (named release). I downloaded the sourcefile (which is in my home directory and named: opencv-2.3.1), and now I want to run this
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
where I use:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/markus/opencv-2.3.1
But the Terminal keeps telling me, that this source directory does not exist!?
So what I am doing wrong?
CMAKE_INSTALL_PREFIX defines where to distribute the binary to after its compiled and linked, it defaults to good place (/usr/local/) so avoid defining it
You are leaving out the trailing .. in your cmake command which tells it where to get the source code hence the error message
Here are the typical steps when installing from source code any project which uses cmake
if you see a file :
CMakeLists.txt
in the src directory this indicates it wants you to use cmake
0 cd into dir where your expanded source code lives
1 mkdir build # make a build dir (initially empty)
2 cd build
3 cmake .. # NOTE those little .. which declares relative path to src dir
which says populate current dir (build) with compiled code
and get the source code and configs from parent directory (..)
4 examine the output, if it looks successful go to step 5
if it has errors you may need to install upstream dependent
libraries then try cmake again
5 make -j4 # compile source, -j speeds up by using multicore
6 sudo make install <-- only if above step 4 and 5 are OK
You can do everything cmake related from command line, yet its GUI can be quite handy especially with an unfamiliar project. In above instead of typing :
cmake ..
its GUI version is :
cmake-gui ..
in the GUI its easy to toggle on/off settings like to build examples or not ... the values column on the right is editable ... if you changed settings in the gui at bottom hit button Configure then when its done hit Generate to perform same as the normal cmake .. now return to step 4 above to do the compile
I am trying to follow this tutorial on wrapping C++ code for python for Windows.I installed python.Downloaded the latest version of boost(1_55).First I ran bootstrap.bat to build bjam.exe.Next, I configured boost_1_55_0\tools\build\v2\user-config.jam to use msvc10 compiler and added the path to python installation.
Now,based on the tutorial :
Now we are ready... Be sure to cd to libs/python/example/tutorial
where the tutorial "hello.cpp" and the "Jamroot" is situated.
Finally:
bjam
Trying to run bjam in that directory gives me : "bjam is not recognized as internal or external command" error.What have I missed here? Should user-config.jam reside in another location?Or bjam added to system path?
UPDATE:
Ok.Thanks to #john I had to add bjam to system path.But now,running it,hello_ext.lib is created in \boost_1_55_0\libs\python\example\tutorial\bin\msvc-11.0\debug but not DLL.Based on the tutorial I should get DLL file for the extension.Now, I am not sure how python links with extension.But if I assume it does like C++ then it should have linked with hello_ext.lib.But if run :
python hello.py
which contains imported method from the extension ,the python runtime crashes.Isn't there a comprehensive tutorial on this workflow?Boost doc sucks completely on this.
This worked for me:
1.) unzip boost_1_55_0.zip
2.) Prepare to use the Boost Library Binaries
Go to the boost_1_55_0 root directory and open a command prompt and type following commands:
Bootstrap
3.) Find user-config.jam:
Type following in the command prompt:
ECHO %HOMEDRIVE%%HOMEPATH%
4.) If the user-config.jam is in your homedrive directory please change it there as followed:
ATTENTION:
The .jam language rates a “whitespace” as a separation of arguments!
# -------------------
# MSVC configuration.
# -------------------
# Configure msvc (default version, searched for in standard locations and PATH).
# using msvc ;
# Configure specific msvc version (searched for in standard locations and PATH).
using msvc : 10.0 : C:\\app\\tools\\MSVisualStudio2010\\VC\\bin\\cl.exe ;
….
# ---------------------
# Python configuration.
# ---------------------
# Configure specific Python version.
# using python : 3.1 : /usr/bin/python3 : /usr/include/python3.1 : /usr/lib ;
using python
: 2.5 # Version
: C:\\app\\tools\\Python25\\python.exe # Python Path
: C:\\app\\tools\\Python25\\include # include path
: C:\\app\\tools\\Python25\\libs # lib path(s)
: <define>BOOST_ALL_NO_LIB=1
;
5.) Build the Libraries AFTER configuration!!
Go to the boost_1_55_0 root directory and open a command prompt and type following commands:
.\b2
6.) Copy the user-config.jam to \boost_1_55_0\libs\python\example\tutorial
7.) Go further to \boost_1_55_0\stage\lib\
Rename libboost_python-vc100-mt-gd-1_55.lib to boost_python-vc100-mt-gd-1_55.lib and copy it to
\boost_1_55_0\libs\python\example\tutorial
8.) Now you should have all of these files in the \boost_1_55_0\libs\python\example\tutorial directory
hello.cpp
hello.py
user-config.jam
Jamroot
boost_python-vc100-mt-gd-1_55.lib
bjam.exe
9.) Open a command prompt in \boost_1_55_0\libs\python\example\tutorial
And type following command:
bjam
10.) After successful building..
You should have this file in the directory:
hello_ext.dll
rename this file to:
hello_ext.pyd