How to build NLopt on Windows - makefile

I'm trying to build NLopt on Windows. To do so, I open Visual Studio 2017 Developer Command Prompt and then:
>cd C:\Users\m3\repos\
>git clone git://github.com/stevengj/nlopt
>cd nlopt
>mkdir build
>cd build
>cmake ..
Then I need to run commands make and sudo make install. Of course, Windows doesn't have GNU make, so I want to use Windows nmake as suggested here. But there I cannot find any proper Makefile to use. Am I missing something?
This is the build directory content after running cmake .. command:
>dir
Volume in drive C has no label.
Volume Serial Number is 3874-53A8
Directory of C:\Users\m3\repos\nlopt\build
10/06/2020 09:45 AM <DIR> .
10/06/2020 09:45 AM <DIR> ..
10/06/2020 09:45 AM 51,498 ALL_BUILD.vcxproj
10/06/2020 09:45 AM 278 ALL_BUILD.vcxproj.filters
10/06/2020 09:44 AM <DIR> build_fpclassify
10/06/2020 09:45 AM 24,269 CMakeCache.txt
10/06/2020 09:45 AM <DIR> CMakeFiles
10/06/2020 09:45 AM 7,196 cmake_install.cmake
10/06/2020 09:45 AM 3,449 CPackConfig.cmake
10/06/2020 09:45 AM 3,690 CPackSourceConfig.cmake
10/06/2020 09:45 AM 308 CTestTestfile.cmake
10/06/2020 09:44 AM 99 fpclassify.c
10/06/2020 09:45 AM 57,561 generate-cpp.vcxproj
10/06/2020 09:45 AM 964 generate-cpp.vcxproj.filters
10/06/2020 09:45 AM 57,576 generate-fortran.vcxproj
10/06/2020 09:45 AM 967 generate-fortran.vcxproj.filters
10/06/2020 09:45 AM 11,841 INSTALL.vcxproj
10/06/2020 09:45 AM 520 INSTALL.vcxproj.filters
10/06/2020 09:45 AM <DIR> Matlab
10/06/2020 09:45 AM 10,624 nlopt.sln
10/06/2020 09:45 AM 79,777 nlopt.vcxproj
10/06/2020 09:45 AM 9,916 nlopt.vcxproj.filters
10/06/2020 09:45 AM 904 NLoptConfig.cmake
10/06/2020 09:45 AM 388 NLoptConfigVersion.cmake
10/06/2020 09:45 AM 3,463 NLoptLibraryDepends.cmake
10/06/2020 09:45 AM 4,955 nlopt_config.h
10/06/2020 09:45 AM 12,073 PACKAGE.vcxproj
10/06/2020 09:45 AM 520 PACKAGE.vcxproj.filters
10/06/2020 09:45 AM 11,315 RUN_TESTS.vcxproj
10/06/2020 09:45 AM 522 RUN_TESTS.vcxproj.filters
10/06/2020 09:45 AM <DIR> src
10/06/2020 09:45 AM <DIR> test
10/06/2020 09:45 AM 50,952 ZERO_CHECK.vcxproj
10/06/2020 09:45 AM 521 ZERO_CHECK.vcxproj.filters
27 File(s) 406,146 bytes
7 Dir(s) 274,515,578,880 bytes free

Well, I finally built it by opening the nlopt.sln Visual Studio Solution file inside build directory by Visual Studio. Then, using the menu Build > Build Solution for both debug and release modes ...

Related

Check if mac executable has debug info

I want to make sure my executable has debug info, trying the linux equivalent doesn't help:
$ file ./my_lovely_program
./my_lovely_program: Mach-O 64-bit executable arm64 # with debug info? without?
EDIT (from the answer of #haggbart)
It seems that my executable has no debug info (?)
$ dwarfdump --debug-info ./compi
./compi: file format Mach-O arm64
.debug_info contents: # <--- empty, right?
And with the other option, I'm not sure:
$ otool -hv ./compi
./compi:
Mach header
magic cputype cpusubtype caps filetype ncmds sizeofcmds flags
MH_MAGIC_64 ARM64 ALL 0x00 EXECUTE 19 1816 NOUNDEFS DYLDLINK TWOLEVEL WEAK_DEFINES BINDS_TO_WEAK PIE
This is very weird because I can perfectly debug it with lldb
(lldb) b main
Breakpoint 1: where = compi`main + 24 at main.cpp:50:9, address = 0x0000000100018650
(lldb) run
Process 6067 launched: '/Users/oren/Downloads/compi' (arm64)
Process 6067 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100018650 compi`main(argc=3, argv=0x000000016fdff7b8) at main.cpp:50:9
47 /*****************/
48 int main(int argc, char **argv)
49 {
-> 50 if (argc == 3)
51 {
52 const char *input = argv[1];
53 const char *output = argv[2];
Target 0: (compi) stopped.
Mach-O isn't like ELF: Its debug info is "sold separately" in a .dSYM file.
When you compile with -g you'll see a file gets generated along side your output, such that:
(~) gcc a.c -o /tmp/a -g2
(~) %ls -lFd /tmp/a /tmp/a.dSYM
-rwxr-xr-x 1 morpheus wheel 34078 Dec 6 12:56 /tmp/a*
drwxr-xr-x 3 morpheus wheel 96 Dec 6 12:56 /tmp/a.dSYM/
The .dSYM is a bundle (i.e. a directory structure) whose Contents/Resources/DWARF has the "companion file":
(~) %file /tmp/a.dSYM/Contents/Resources/DWARF/a
/tmp/a.dSYM/Contents/Resources/DWARF/a: Mach-O 64-bit dSYM companion file arm64
(~) %jtool2 -l /tmp/a.dSYM/Contents/Resources/DWARF/a | grep UUID
LC 00: LC_UUID UUID: BDD5C13E-F7B8-3B4D-BAF9-14DF3CD03724
(~) %jtool2 -l /tmp/a | grep UUID
LC 09: LC_UUID UUID: BDD5C13E-F7B8-3B4D-BAF9-14DF3CD03724
tools like lldb can figure out the debug data by trying for the companion file directory (usually in same location as the binary, or specified in a path), and then check the LC_UUID matches. This enables you to ship the binary without its dSym, and use the dSym when symbolicating a crash report (this is what Apple does). The debug info includes all local variable names, as well as debug_aranges (addr2line), etc:
(~) %jtool2 -l /tmp/a.dSYM/Contents/Resources/DWARF/a | grep DWARF
LC 07: LC_SEGMENT_64 Mem: 0x100009000-0x10000a000 __DWARF
Mem: 0x100009000-0x10000921f __DWARF.__debug_line
Mem: 0x10000921f-0x10000924f __DWARF.__debug_aranges
Mem: 0x10000924f-0x1000093dc __DWARF.__debug_info
Mem: 0x1000093dc-0x100009478 __DWARF.__debug_abbrev
Mem: 0x100009478-0x100009590 __DWARF.__debug_str
Mem: 0x100009590-0x1000095e8 __DWARF.__apple_names
Mem: 0x1000095e8-0x10000960c __DWARF.__apple_namespac
Mem: 0x10000960c-0x100009773 __DWARF.__apple_types
Mem: 0x100009773-0x100009797 __DWARF.__apple_objc
If you really want to get of any debug info - including, say, local function symbols (which are included by default in the binary), strip -d -x is your friend. This operates on the binary.
Note that running "dsymutil" (As suggested in other answers) can be a bit misleading, since in order to display information it will track down the accompanying dSym - which will be present on your machine, but not if you move the binary elsewhere.
If you run :
dsymutil -s ./my_lovely_propgram | grep N_OSO
and it shows output, it means there is debug info.

make: *** No rule to make target for memtier_benchmark performance tool

I am trying to compile and install the memtier_benchmark database performance benchmark tool for Redis and I am running into the error: make: *** No rule to make target , even though a Makefile for it does exist in the directory.
rw-rw-r-- 1 labuser labuser 2094 Jun 1 22:00 Makefile.am
-rw-rw-r-- 1 labuser labuser 75172 Jun 1 22:01 Makefile.in
The write permissions appear to be okay, not sure what could be the problem, but there is a nasty error I do not understand when I run ./configure:
./configure: line 16460: syntax error near unexpected token LIBEVENT_OPENSSL,' ./configure: line 16460: ` PKG_CHECK_MODULES(LIBEVENT_OPENSSL,'
The files you list are not makefiles. Makefiles are named Makefile or makefile (or, if you're using GNU make, GNUmakefile). That's why when you run make, it says "no rule to make target", because there's no makefile defining that rule.
The files Makefile.am and Makefile.in are not actually makefiles, they're inputs to autotools which will generate your makefile. The way you're supposed to use them is to run the ./configure script. Once you do that, that script will convert the Makefile.in file into a Makefile. Then you can run make.
./configure
make
There should be an INSTALL or README file that came with the source code that describes this process.

Collapse all :glob:-discovered files into one TOC entry

I've got something like this:
.. toctree::
:maxdepth: 2
:caption: Contents:
:hidden:
:glob:
docs
frontend
backend
tools/*
I'd like all the documents found in the tools directory to collapse into one expandable sidebar TOC entry. Should be possible, but I can't find a clue.
I use sphinx_rtd_theme.
To put it another way: suppose I have a very long document like this (tools.rst):
Section 1
*********
Subsection 1
============
Subsection 2
============
Subsection 3
============
How am I supposed to split it by the subsection and preserve the document structure, without resorting to includes, which don't sit well with Sphinx anyway.
source/index.rst:
.. toctree::
:maxdepth: 2
:caption: Contents:
:glob:
tools/_tools
docs
frontend
backend
tmp/*
Old source/tools/_tools.rst:
Notes on tools
**************
.. include:: black.rst
.. include:: docker.rst
.. include:: git_hooks.rst
.. include:: github_webhooks.rst
.. include:: mypy.rst
.. include:: pipm.rst
.. include:: poetry.rst
.. include:: sphinx.rst
.. include:: uvicorn.rst
New source/tools/_tools.rst:
Notes on tools
**************
.. toctree::
:maxdepth: 2
:glob:
*
The new one renders exactly like the old one, and is more versatile an a lot cleaner.

Makefile with msys on Windows strange behaviour using the include directive (On linux works perfectly)

Problems using the INCLUDE directive inside a makefile using msys.
I added MSYS in PATH and is ok until here:
PS C:\Users\Roxanji> Get-Command make
CommandType Name Version Source
----------- ---- ------- ------
Application make.exe 0.0.0.0 C:\Program Files\msys\bin\make.exe
PS C:\Users\Roxanji> Get-Command bash
CommandType Name Version Source
----------- ---- ------- ------
Application bash.exe 0.0.0.0 C:\Program Files\msys\bin\bash.exe
Makefile example:
-include a1
a1:
#echo something: > a1
.PHONY: clean
clean:
$(RM) a1
On Windows cmd/powershell:
PS C:\Users\Roxanji\eclipse-workspace\prototype\tst> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 15.11.2020 05:53 81 Makefile
PS C:\Users\Roxanji\eclipse-workspace\prototype\tst> make
make.exe": /c/Users/Roxanji/eclipse-workspace/prototype/tst/"C:/Program Files/msys/bin/make.exe": Command not found
PS C:\Users\Roxanji\eclipse-workspace\prototype\tst> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 15.11.2020 06:03 11 a1
-a---- 15.11.2020 05:53 81 Makefile
On Windows using bash from msys:
PS C:\Users\Roxanji\eclipse-workspace\prototype\tst> bash
bash.exe"-3.1$ pwd
/c/Users/Roxanji/eclipse-workspace/prototype/tst
bash.exe"-3.1$ ls
Makefile
bash.exe"-3.1$ make
make: Nothing to be done for `something'.
bash.exe"-3.1$ ls
Makefile a1
bash.exe"-3.1$
Facts using cmd/powershell:
The file 'a1' is generated.
Command not found message.
Facts using msys bash:
-The file 'a1' is generated.
What I think is going on?
I see that there are some mixing of windows slash "\" and unix slash
"/"
I see that the make "location" seems different under bash from msys:
bash.exe"-3.1$ which make
/usr/bin/make.exe
I see that also under msys/bash there is this message make: Nothing to be done for 'something'.
I think that when make hits include another make.exe is spawned to read this other file, but is called from within make, that has a different PATH for make, and this causes some problems.
Someone can give explanations about this phenomena??
Edit 1:
using powershell:
PS C:\Users\Roxanji\eclipse-workspace\prototype\tst> make -np | grep MAKE_COMMAND
MAKE = $(MAKE_COMMAND)
MAKE_COMMAND := /c/Users/Roxanji/eclipse-workspace/prototype/tst/"C:/Program Files/msys/bin/make.exe"
Shouldn't the MAKE_COMMAND variable bee equal to just "make"?
like: MAKE_COMMAND := make ?
Edit 2:
I think the problem can be tracked down to the fact that I can't run msys.bat under C:\Program Files\ because apparently there is a space in "Program files"??
As mentioned, the most reliable solution on Windows is a native Windows make build. I was able to run your Makefile directly from Powershell using such native build without any errors, regardless of make being located in a directory with space:
> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 11/26/2020 4:11 PM 86 Makefile
> & 'C:\Program Files\make\make.exe'
make: Nothing to be done for 'something'.
> ls
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 11/26/2020 4:17 PM 13 a1
-a--- 11/26/2020 4:11 PM 86 Makefile
MAKE_COMMAND also looks good:
> & 'C:\Program Files\make\make.exe' -np | ? { $_ -match "MAKE_COMMAND" }
MAKE = $(MAKE_COMMAND)
MAKE_COMMAND := C:/Program Files/make/make
All tests done with:
> & 'C:\Program Files\make\make.exe' --version
GNU Make 4.2.1
Built for Windows32
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Built directly from source using Visual Studio.

How to include pages generated at build time?

I seek to make an "API Reference" page exposing genindex.html and py-modindex.html; problem is, I rather the entire page not be just clickable links to said pages, but to actually include their contents. We can do this with a README - however, README.rst exists in source/, whereas genindex.html is only in build/, so below don't work:
.. include:: modindex
.. include:: genindex
.. include:: modindex.rst
.. include:: genindex.rst
.. include:: ../build/genindex.html
Can this be accomplished?

Resources