Makefile command line arguments confused with MinGW directory paths - command-line

I'm trying to run a make all command but I get a very confusing error, it seems as if the arguments from 'cl' are mistaken as directory paths in MinGW. The output I'm getting:
cl /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo /O2 -DN
DEBUG -DUSE_CBC -DUSE_CLP /D__WIN32__ /Iinclude\\src\\windows /DGFLAGS_DLL_DECL=
/DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /Iinclude /I. -DUSE_GLOP -
DUSE_BOP -c examples\\cpp\\costas_array.cc /Foobjs\\costas_array.obj
That's the cl command, not the warnings and errors (note that cl /EHsc actually gets mistaken for 'C:/MinGW/MSYS/1.0/EHsc', etc...):
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/EHsc', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/EHsc' ignored
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/MD', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/MD' ignored
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/nologo', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/nologo' ignored
... etc ... Until there's the fatal error at the end
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/I.', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/I.' ignored
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/Foobjs/costas_a
rray.obj' ignored
costas_array.cc
examples\cpp\costas_array.cc(27): fatal error C1083: Cannot open include file: '
ortools/base/callback.h': No such file or directory
make: *** [objs\\costas_array.obj] Error 2
Any help about why is this happening would be highly appreciated, I am not very experienced in this matter.

It's the MSYS shell doing these translations for you in an attempt of being helpful.
With the tools typically used in this shell, it's no problem because arguments/options start with a - or -- (the Unix and/or GNU convention). It starts getting into your way as soon as you need command-line tools following the Microsoft convention for options and flags, using /.
Unfortunately, for the original MSYS, I'm not aware of a way to disable this translation. But there is one for MSYS2, see the question I asked about it: You just need to set an environment variable, e.g.
export MSYS2_ARG_CONV_EXCL=\*
So, my suggestion would be you upgrade your tools to MSYS2 and use this.

Related

How to build Swift project on NixOS?

I'm trying to build a simple Swift project on NixOS. Here are the steps to reproduce:
git clone https://github.com/PerfectlySoft/PerfectTemplate.git
cd PerfectTemplate
touch shell.nix
Add shell.nix with following contents:
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "swift-env";
buildInputs = [
openssl
stdenv
binutils
cmake
pkgconfig
curl
glibc
icu
libblocksruntime
libbsd
libedit
libuuid
libxml2
ncurses
sqlite
swig
];
}
Running nix-shell --pure shell.nix and from there swift build, gives me:
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-target’
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fmodule-name=PerfectCZlib’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fmodules-cache-path=/home/dmi3y/Dev/Swift/PerfectTemplate/.build/x86_64-unknown-linux/debug/ModuleCache’
gcc: error: unrecognized command line option ‘-fblocks’
I'd appreciate any help with this as I'm pretty much new to nix-shell and NixOS.
EDIT:
I changed my shell.nix to this:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "swift-env";
buildInputs = with pkgs; [
openssl
clang
swift
];
shellHook = ''
CC=clang
'';
}
However, when I run nix-shell followed by swift build, I'm now getting:
[1/25] Compiling PerfectCZlib zutil.c
[2/25] Compiling PerfectCZlib uncompr.c
[3/25] Compiling PerfectCZlib inftrees.c
[4/25] Compiling PerfectCZlib inflate.c
[5/25] Compiling PerfectCZlib trees.c
[6/25] Compiling PerfectCZlib inffast.c
[7/25] Compiling PerfectCZlib infback.c
[8/25] Compiling PerfectCZlib gzwrite.c
/nix/store/iz6k7x3l14ykr56crz3dizas1rrkcyzr-clang-wrapper-7.1.0/resource-root/include/module.modulemap:24:8: error: redefinition of module '_Builtin_intrinsics'
# warning _FORTIFY_SOURCE requires compiling with optimization (-O)
^
1 warning and 3 errors generated.
1 warning and 3 errors generated.
Full log can be found here.
This is now looks like a missing library dependency or a version conflict.
For the record, here's additional information about my setup that might shed more light:
$ nix-channel --list
home-manager https://github.com/rycee/home-manager/archive/master.tar.gz
nixos https://nixos.org/channels/nixos-19.09
$ nix-shell --run 'swift -version'
Swift version 5.0.2 (swift-5.0.2-RELEASE)
Target: x86_64-unknown-linux-gnub
After searching the web I found a Jira issue for Swift compiler and this specific comment. I decided to exclude clang from dependencies and only include swift, since this combination seem to be conflicting:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "swift-env";
buildInputs = with pkgs; [
openssl
swift
];
shellHook = ''
CC=clang
'';
}
And that worked! I was finally able to build the project!
Since your using the --pure option, nothing from your previous environment will be imported into the shell. This includes the swift binary itself. So first I would add swift to the buildInputs.
The error your getting indicates that gcc doesn't even understand the command line options being passed. I don't know anything about Swift, but after seeing that I assumed that it needs a different compiler. Sure enough, after a quick search it looks like it is llvm based. You will thus need to also add clang to your build inputs. In addition, you'll need to use mkShell instead of mkDerivation to setup the proper environment.
The former is a wrapper to the latter that is specifically designed to set up a nix-shell, and ensures the environment is handled correctly. You'll need to pass in the shellHook attribute to override the default c compiler to clang using the CC envvar. The shellHook is a way of running arbitrary commands at the start of the shell.
As a final note, the nix-shell command searches for shell.nix by default so you don't have to pass it as an argument. If shell.nix does not exist, then it will try default.nix. If neither exist, then you'll have to explicitly specify the nix expressions location.
TLDR
to put it all together:
# a more idiomatic way to import nixpkgs, overridable from the cmdline
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "swift-env";
buildInputs = with pkgs; [
# your other inputs
clang
swift
];
shellHook = ''
CC=clang
'';
}
Just to be sure my logic was correct I downloaded the repo and gave it go. Everything compiles and runs successfully.

Error in ./configure step in installation of libpqxx

this is a bit of a long shot but:
I'm following this guide: https://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm
But when running ./configure I get the following error:
(previous checking lines omitted for brevity)
checking for main in -lpq... yes
checking for PQexec in -lpq... yes
checking for correct C++ linkage of basic libpq functions...
sed: character class syntax is [[:space:]], not [:space:]
configure: error:
Linking a call to libpq failed in C++, even though it succeeded in C. If your
C and C++ compilers are very different beasts, this may mean that we do not have
the right options for linking with it after all.
Read the config.log file for more detailed information. Look for the last error
message, which may be several pages up from the end of the file.
And the configure.log file looks like this:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by libpqxx configure 4.0, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
## --------- ##
(some lines omitted)
configure:3039: g++ -V >&5
g++: error: unrecognized command line option '-V'
g++: fatal error: no input files
compilation terminated.
configure:3050: $? = 1
configure:3039: g++ -qversion >&5
g++: error: unrecognized command line option '-qversion'; did you mean '--version'?
g++: fatal error: no input files
compilation terminated.
(some lines omitted)
configure:7629: gcc -E conftest.c
conftest.c:11:10: fatal error: ac_nonexistent.h: No such file or directory
#include <ac_nonexistent.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
(some lines omitted)
configure:8319: gcc -c -g -O2 -fno-rtti -fno-exceptions conftest.c >&5
cc1: warning: command line option '-fno-rtti' is valid for C++/ObjC++ but not for C
(some lines omitted)
configure:16424: g++ -o conftest -g -O2 -L/usr/lib/x86_64-linux-gnu conftest.cpp >&5
/tmp/ccfFBf4K.o: In function `main':
/home/peter/libpqxx-4.0/conftest.cpp:44: undefined reference to `PQexec'
collect2: error: ld returned 1 exit status
(some liens omitted)
I don't believe I have any packages missing. I have the newest version of g++, psql and libpqxx installed.
I have updated and upgraded all packages on my system.
I have crawled the web for solutions to this error, but I have no clue what is wrong.
Do you have an idea where I can go from here?
There hasn't been a tarball release of libpqxx at the old spot in a long time, so the tutorial you used with its wget command to download the tarball is very outdated.
The issue you encountered looks related to this issue and appears to have been fixed in this commit:
commit 85e9336740475be25ed19924cca0961f7d844c4b
Author: Jeroen Vermeulen <jtvjtv#gmail.com>
Date: Thu Jun 1 11:39:08 2017 +0700
Fix #13: not linking to libpq.
This was that annoying interaction between autoconf, m4, GNU sed syntax,
and the shell which broke the "remove redundant -lpq options" code in
the configure script.
Solution: forget about GNU sed's "[[:space:]]" syntax, and just look for
a literal space. There aren't going to be any tabs, newlines,
non-breaking spaces, etc. there in even a moderately sane world.

Convert matlab make from linux version to windows version

I have this linux makefile from public code and now I'm trying to use it on Windows
http://pastebin.com/gSqRFUvQ
This is what I have so far.
http://pastebin.com/iHugE5Z6
But I get an error on line 80.
echo "#include \"../src/gconv.cu\"" > "matlab/mex/gconv.cpp"
"/cygdrive/C/Program Files/Matlab2014b/bin/win64/mex" -lmwblas -largeArrayDims "matlab/mex/gconv.cpp" matlab/src/bits/im2col.obj matlab/src/bits/pooling.obj matlab/src/bits/normalize.obj -o "matlab/mex/gconv.mexw64" 2> >(sed 's/^\(.*\)(\([0-9][0-9]*\)): \([ew].*\)/\1:\2: \3/g' >&2)
Unknown MEX argument '-o'.
Makefile:79: recipe for target 'matlab/mex/gconv.mexw64' failed
make: *** [matlab/mex/gconv.mexw64] Error 127
Basically the argument -o doesn't exist. I'm sure what the author wanted by that parameter. But I think it should be -output since it will produce .mew64 file. If I change that into "-output", it gets error in the middle.
echo "#include \"../src/gconv.cu\"" > "matlab/mex/gconv.cpp"
"/cygdrive/C/Program Files/Matlab2014b/bin/win64/mex" -lmwblas -largeArrayDims "matlab/mex/gconv.cpp" matlab/src/bits/im2col.obj matlab/src/bits/pooling.obj matlab/src/bits/normalize.obj -output "matlab/mex/gconv.mexw64" 2> >(sed 's/^\(.*\)(\([0-9][0-9]*\)): \([ew].*\)/\1:\2: \3/g' >&2)
Building with 'Microsoft Visual C++ 2012'.
gconv.cpp
c:\cygwin64\home\denny\jaderberg-eccv2014_textspotting-dbe823e3c642\matconvnet\matlab\src\bits/mexutils.h(132) : error C3861: 'snprintf': identifier not found
c:\cygwin64\home\denny\jaderberg-eccv2014_textspotting-dbe823e3c642\matconvnet\matlab\src\bits/mexutils.h(147) : error C3861: 'snprintf': identifier not found
c:\cygwin64\home\denny\jaderberg-eccv2014_textspotting-dbe823e3c642\matconvnet\matlab\mex\../src/gconv.cu(228) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
c:\cygwin64\home\denny\jaderberg-eccv2014_textspotting-dbe823e3c642\matconvnet\matlab\mex\../src/gconv.cu(381) : warning C4267: 'argument' : conversion from 'size_t' to 'const int', possible loss of data
c:\cygwin64\home\denny\jaderberg-eccv2014_textspotting-dbe823e3c642\matconvnet\matlab\mex\../src/gconv.cu(459) : warning C4267: 'argument' : conversion from 'size_t' to 'const int', possible loss of data
c:\cygwin64\home\denny\jaderberg-eccv2014_textspotting-dbe823e3c642\matconvnet\matlab\mex\../src/gconv.cu(481) : warning C4267: 'argument' : conversion from 'size_t' to 'const int', possible loss of data
Makefile:79: recipe for target 'matlab/mex/gconv.mexw64' failed
make: *** [matlab/mex/gconv.mexw64] Error 127
Is it not possible to use this on windows? Could anyone shed some light?
You should be now able to use the same networks in newer MatConvNet versions as a Windows support was added (even though there are still some glitches in some configurations...).
Also the bugs which you are reporting here were fixed as well (at that time the code was not fixed for the MSC compiler).

Unexpected EOF when linking Arduino project in Eclipse on OS X

I have been trying to link Arduino and Eclipse, and I feel like I'm close.
Where should I start looking for this?
Similar errors have been caused by extra/incomplete quote blocks (according to google searches). I have already dug through my AVR linker settings looking for quotes, but haven't had much luck.
Am I looking in the right place?
Which files should I check?
I have already looked in the file I have written myself (in this case, the basic Arduino blink program).
**** Build of configuration Release for project C64_Arduino1 ****
make all
Building target: C64_Arduino1.elf
Invoking: AVR C++ Linker
avr-gcc --cref -s -Os -o"C64_Arduino1.elf" ./C64_Arduino1.o ./CDC.o ./HID.o
./HardwareSerial.o ./Print.o ./Stream.o ./Tone.o ./USBCore.o ./WInterrupts.o ./WMath.o ./WString.o ./malloc.o ./wiring.o ./wiring_analog.o ./wiring_digital.o ./wiring_pulse.o
./wiring_shift.o -l"Arduino_Mega_2560_or_Mega_ADK" -lm -L/Users/Chet/Desktop/Chet's Shit/Side Projects/Programming/C64_Arduino1/Release -L"/Users/Chet/Desktop/Chet's Shit/Side
Projects/Programming/C64_Arduino1" -mmcu=atmega2560
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
make: *** [C64_Arduino1.elf] Error 2
**** Build Finished ****
EDIT:
I have commented out all of my code (including #include's) except the main (which is empty) and I still get the error. I have set up my IDE as specified Here and also Here. Still nothing.
Looking at the actual error message:
/bin/sh: -c: line 0: unexpected EOF while looking for matching `"'
/bin/sh: -c: line 1: syntax error: unexpected end of file
I can see that the problem is most likely due to some kind of Makefile syntax error.
When you write a make rule such like:
foo:
touch foo
What make does, it first checkes whether file called foo exists already, if not, then it runs command /bin/sh -c 'touch foo'. So the line where we said touch foo should have valid shell script syntax.
Looking at the command that you ended up running:
avr-gcc --cref -s -Os -o"C64_Arduino1.elf" ./C64_Arduino1.o ./CDC.o ./HID.o
./HardwareSerial.o ./Print.o ./Stream.o ./Tone.o ./USBCore.o ./WInterrupts.o ./WMath.o ./WString.o ./malloc.o ./wiring.o ./wiring_analog.o ./wiring_digital.o ./wiring_pulse.o
./wiring_shift.o -l"Arduino_Mega_2560_or_Mega_ADK" -lm -L/Users/Chet/Desktop/Chet's Shit/Side Projects/Programming/C64_Arduino1/Release -L"/Users/Chet/Desktop/Chet's Shit/Side
Projects/Programming/C64_Arduino1" -mmcu=atmega2560
I can see that the issue is with the ' character in some of the directory paths. You should either escape it (as in "/Users/Chet/Desktop/Chet\'s Shit") or, as a quick work-around symlink or move the directory.
As a general methodology tip, you should first check whether everything works in CLI, and then move on to teaching Eclipse what commands it should run.
Also, I would consider using the tool called ino instead of make, it might just work with minimum configuration. I have had some experience replacing Arduino IDE with just a Makefile, but it gets hairy when you need to use different boards and perhaps several connected at the same time. Give ino a try, it looks quite promising.

Why can't MATLAB deploytool output exe file?

deploytool works well until creating exe file using mbuild then get this error:
Executing command: mbuild -O -v -output "U1" -I"e:\Mat2009\work\ntst1\U1\src" "e:\Mat2009\work\ntst1\U1\src\U1_main.c" "e:\Mat2009\work\ntst1\U1\src\U1_delay_load.c" "e:\Mat2009\work\ntst1\U1\src\U1_mcc_component_data.c" -link exe -env MCR_DELAYLOAD=/delayload:mclmcrrt710.dll -env
MCR_DELAYLIB=delayimp.lib -outdir "e:\Mat2009\work\ntst1\U1\src"
Error: An error occurred while shelling out to mbuild (error code = -1).
Unable to build executable.
??? Error using ==> mcc
Error executing mcc, return status = 1 (0x1).
How can I resolve this error?
This error looks similar to an error I encountered once (after upgrading to 2012b), I cannot recall the source but I found two potential solutions:
Make sure there are no spaces in the path to the compiler
Try building a few times and cross your fingers
Given the time frame I had I chose to go for option two and after 5-10 attempts it suprisingly worked.
have found that COMSPEC env. var had a wrong value, so I deleted the wrong path, restarted MATLAB then it worked well.