Dealing with "C compiler cannot create executables" in Cygwin - c++

Whatever I try to compile in Cygwin I get the following output:
checking for mingw32 environment... no
checking for EMX OS/2 environment... no
checking how to run the C preprocessor... gcc -E
checking for gcc... gcc
checking whether the C compiler (gcc ) works... no
configure: error: installation or configuration problem: C compiler cannot creat
e executables.
The last few lines of the logfile look like this:
configure:2810: checking for EMX OS/2 environment
configure:2822: gcc -c conftest.c 1>&5
configure: In function `main':
configure:2818: error: `__EMX__' undeclared (first use in this function)
configure:2818: error: (Each undeclared identifier is reported only once
configure:2818: error: for each function it appears in.)
configure: failed program was:
#line 2815 "configure"
#include "confdefs.h"
int main() {
return __EMX__;
; return 0; }
configure:2838: checking how to run the C preprocessor
configure:2859: gcc -E conftest.c >/dev/null 2>conftest.out
configure:2943: checking for gcc
configure:3056: checking whether the C compiler (gcc ) works
configure:3072: gcc -o conftest conftest.c -llib 1>&5
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find
-llib
collect2: ld returned 1 exit status
configure: failed program was:
#line 3067 "configure"
#include "confdefs.h"
main(){return(0);}
This is a fresh Cygwin install with G++ and a bunch of other devtools added. Any idea what I need to do to get this thing working?
Update 0: Nick, your link to http://www.geektimes.com/linux/troubleshooting/c-cant-create-executables.html was tried already - unfortunately this instructions are for redhat and do not seem to apply to cygwin.

Your Configure is wrong.
Usually autoreconf -f helps. If not you need to check the failing rule and fix it.

The '-llib' seems a bit unusual to me, but I'm far from an expert. Just out of curiosity is autoconf installed? I had some problems similar to this until I installed autoconf. It seems like the configure script is incorrectly generating a '-llib' value but it's hard to say why based on just the snippets posted.

When I've had this problem, it has been a link error caused by Cygwin looking for "library.o" instead of "library.obj" or "library.so" instead of "library.dll".

Related

Can anyone explain how to use OpenACC in GCC?

I am using WSL Ubuntu. And use GCC to compile my C++ code.
I am trying to use OpenACC to parallelize my code. I heard that I can use OpenACC with GCC.
So after I install Ubuntu, I installed GCC.
And then I typed as follows:
$ g++ -fopenacc -o t testfile.cpp
As far as I know, -fopenacc should enable me to use OpenACC inside my code.
However, I got an message saying:
lto-wrapper: fatal error: could not find accel/nvptx-none/mkoffload in /usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/9/:/usr/lib/gcc/x86_64-linux-gnu/ (consider using ‘-B’)
So I guess I missed something.
Does anyone know how to use OpenACC with GCC?
Edited:
I tried:
sudo apt-get install gcc-9-offload-nvptx
And then the error message is now changed to:
lto1: error: ‘-fcf-protection=full’ is not supported for this target
mkoffload: fatal error: x86_64-linux-gnu-accel-nvptx-none-gcc-9 returned 1 exit status
compilation terminated.
lto-wrapper: fatal error: /usr/lib/gcc/x86_64-linux-gnu/9//accel/nvptx-none/mkoffload returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
I got one step further with:
gcc-10 -O2 -ffast-math -fopenacc -fopt-info-all-omp -fcf-protection=none -foffload=nvptx laplace2dkernels.c
but just to find the next problem:
gcc-10: fatal error: GCC is not configured to support nvptx as offload target
compilation terminated
So it seems they only compiled it for AMD GCN.
If you use
gcc-10 -O2 -ffast-math -fopenacc -fopt-info-all-omp -fcf-protection=none -foffload=nvptx-none laplace2dkernels.c
>laplace2dkernels.c:74:9: optimized: assigned OpenACC seq loop parallelism
>/usr/bin/ld: /tmp/ccYd0cZe.crtoffloadtable.o: warning: relocation against >`__offload_vars_end' in read-only section `.rodata'
It compiles but then when running it misses:
libgomp: while loading libgomp-plugin-gcn.so.1: libgomp-plugin-gcn.so.1: cannot open shared object file: No such file or directory
I do not need to install those libraries because I want to get it to run with my Nvidia card.
With the PGI compilers everything worked fine.
NOTE: I am also using WSL and special NVIDIA drivers to allow for GPU passthrough.
Here's what worked for me for a Tiny C++ stencil code with OpenACC directives, after installing gcc-10-offload-nvptx:
g++ -c -g -O -fopenacc -foffload=nvptx-none -fcf-protection=none -foffload=-misa=sm_35 -fno-stack-protector stencil_acc.cxx
g++ -o stencil_acc -g -O -fopenacc -foffload=nvptx-none -fcf-protection=none -foffload=-misa=sm_35 -fno-stack-protector util.o stencil_acc.o

c++ / g++ - Error: Unknown pseudo-op: `. loc'

I am trying to configure my computer to learn C++.
I have errors and warnings once I run gcc from the terminal to call hello.cpp.
C:\Users\Mathieu>gcc -g hello.cpp -o hello -lm
I am using a Windows computer / windows 7 (64 bits) / IDE: Sublime text or Visual Studio Code.
What I have done so far by looking for solutions in the web:
I have added into the PATH the address of MinGW and I have added ";" before the previous PATH.
I have also been checking all the PATH by using echo %PATH% into the terminal and checking the environmental variables.
By typing g++ or gcc alone in the terminal, I get "fatal error, no input file", which means gcc and g++ are well detected by the computer.
I have checked g++ and gcc versions, there are equal.
gcc (MinGW.org GCC Build-20200227-1) 9.2.0
gcc (MinGW.org GCC Build-20200227-1) 9.2.0
I have also performed #alisonc recommandation found here by reviewing links.
g++ 4.6.1 compiler error: Error: unknown pseudo-op: `.cfi_personality'
C:\Users\Mathieu>ls 'which g++' -al
ls: which g++: No such file or directory
C:\Users\Mathieu>ls 'which gcc' -al
ls: which gcc: No such file or directory
When I have launched the program from the terminal I get a long list of errors. I am just adding 3 lines to illustrate. I am not sure if that is relevant to add everything, please, see a few ones:
C:\Users\Mathieu\AppData\Local\Temp\ccUFD66I.s:6498: Error: Unknown pseudo-op:
.secrel32
C:\Users\Mathieu\AppData\Local\Temp\ccUFD66I.s:153: Warning: Missing string
C:\Users\Mathieu\AppData\Local\Temp\ccUFD66I.s:153: Error: Rest of line ignored.
First ignored character is `3'.'''
May someone help me ?
Thank you in advance
All the best
Mathieu
Try to run:
g++ -g hello.cpp -o hello -lm

AC_LANG_PROGRAM failed the linker stage because of order of linker option

I am trying to test a C++ library and have to do a little more than the AC_SEARCH_LIBS or AC_CHECK_LIB. However, my linker is picky about the order of the options (g++ version 5.4.0).
My configure.ac contains the following code:
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <api/BamReader.h>], [BamTools::BamReader dummy])],
[TEST_LIBS=="$TEST_LIBS -lbamtools"] [HAVE_BAMTOOLS=1],
[AC_MSG_WARN([libbamtools is not installed])])
I know that the Bamtools are install on my system. This will generate an negative result:
checking api/BamReader.h usability... yes
checking api/BamReader.h presence... no
configure: WARNING: api/BamReader.h: accepted by the compiler, rejected by the preprocessor!
configure: WARNING: api/BamReader.h: proceeding with the compiler's result
checking for api/BamReader.h... yes
configure: WARNING: libbamtools is not installed <-- this line
After some investigation, it appears to be the order of the linker option.
The conftest.cpp file looks like the following:
#include <api/BamReader.h>
int main () {
BamTools::BamReader dummy;
return 0;
}
The autoconf macro is calling
g++ -o conftest -g -O2 -I/usr/local/include/bamtools -L/usr/local/lib/bamtools -lbamtools conftest.cpp/tmp/ccZiV1J9.o: In function `main':
/home/kzhou/coding/tmp/conftest.cpp:24: undefined reference to `BamTools::BamReader::BamReader()'
/home/kzhou/coding/tmp/conftest.cpp:24: undefined reference to `BamTools::BamReader::~BamReader()'
collect2: error: ld returned 1 exit status
If yo switch the order by putting the -lbamtools to the end, then the linker is happy:
g++ -o conftest -g -O2 -I/usr/local/include/bamtools -L/usr/local/lib/bamtools conftest.cpp -lbamtools
I wonder the AC_LANG_PROGRAM needs to be updated? Please comment. So far I have not found a good solution for this problem.
Please reference:
https://nerdland.net/2009/07/detecting-c-libraries-with-autotools/
This looks like you are passing the library in the wrong variable; if you were passing the library in LIBS it would be in the right position because autoconf does the right thing.
Now, the code you pasted has a syntax error too (using == which is a comparison instead of = which is an assignment), and a logical one since TEST_LIBS was a variable used by the specific post you reference. So that is not what is setting -lbamtools in any of the orders.
save_LIBS=$LIBS
LIBS="$LIBS -lbamtools"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([#include <api/BamReader.h>], [BamTools::BamReader dummy])],
[save_LIBS="$LIBS"; HAVE_BAMTOOLS=1],
[AC_MSG_WARN([libbamtools is not installed])])
LIBS=$save_LIBS
this should do what you're looking for, although it's still a bit more complicated than it could be. You could use AC_CHECK_TYPE to just check if BamTools::BamReader is defined.

Compiling CodeViz patch for GCC on 64 bit debian

I am trying to compile CodeViz on 64 bit Debian. However, I am finding that the included patch for GCC causes GCC not to compile. When I extract GCC 4.6 and compile it manually (by running
$ ../gcc-4.6.4/configure --prefix=/home/jeremy/gcc-codeviz --enable-languages=c,c++ --disable-bootstrap
$ make
) it compiles without error. However, when I apply the included patch, it fails with the error
/usr/bin/ld: ../libsupc++/.libs/libsupc++convenience.a(cp-demangle.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
../libsupc++/.libs/libsupc++convenience.a(cp-demangle.o): error adding symbols: Bad value
collect2: ld returned 1 exit status
The patch can be seen here http://pastebin.com/djSQYe5a . It's really not that complicated, doesn't change any build options or includes, and doesn't use any advanced language features. I really don't understand how this causes a linking error which doesn't show up in the vanilla gcc build. Furthermore, the error itself occurs in "cp-demangle.o", which I don't think should even be touched by the patch! My best guess is that it has something to do with the extern int cdepn_dump which is declared, or the declaration of the functions in tree.h.
Any help is appreciated.
This patch can be applied to the source of Debian gcc-4.6
apt-get source gcc-4.6
cp gcc-4.6.2-cdepn.diff gcc-4.6-4.6.3/debian/patches
to rules.patch
nano gcc-4.6-4.6.3/debian/rules.patch
debian_patches += \
libstdc++-pic \
...
gcc-4.6.2-cdepn \
The main error occurs because the function fprintf.
The default compiler flags includes -Wformat -Wformat-security which is what gives this error. Disabled with -Wformat=0 or -Wno-format-security in CPPFLAGS or/and CFLAGS.
Also look to gcc-4.6-4.6.3/debian/patches/fix-warnings.diff for src/gcc/toplev.c and to gcc-4.6-4.6.3/debian/rules2, dpkg-buildflags
just for information.
export DEB_BUILD_MAINT_OPTIONS=hardening=-all,-format
export DEB_CFLAGS_MAINT_APPEND=-fPIC,-Wformat=0,-Wno-format-security
export DEB_CPPFLAGS_MAINT_APPEND=-fPIC,-Wformat=0,-Wno-format-security
export DEB_CXXFLAGS_MAINT_APPEND=-fPIC,-Wformat=0,-Wno-format-security
dpkg-buildflags
dpkg-buildpackage -b -d -rfakeroot -us -uc

If I use g++ as my compiler, how do I scan a c++ file with the clang static analyzer?

I use g++ to compile my C++ project. When I try to use the clang static analyzer (scan-build) to check my code, I get an error:
>> scan-build g++ main.cpp
could not find clang line
How do I use the scan-build tool with g++?
It appears that scan-build is having trouble recognizing "g++" as the compiler command. It expects "clang" or "gcc". If you replace "g++" with "gcc -lstdc++" to build your project, the scan-build tool will work properly.
>> scan-build gcc -lstdc++ main.cpp
main.cpp:7:3: warning: Assigned value is garbage or undefined
int y = x;
^ ~
1 warning generated.
scan-build: 1 bugs found.
scan-build: Run 'scan-view /var/folders/2l/2l6vhCnVFNad-O8ryd5YO++++TI/-Tmp-/scan-build-2011-09-18-2' to examine bug reports.