Is it possible to set such a build command in it, which will compile source via cygwin call?
The default command in preferences is gcc -Wall -o "%e" "%f" which calls MinGW, but some files can be compiled with cygwin version of gcc only (those which have linux specific libs like termios.h etc).
I tried this c:\cygwin\bin\bash -c "gcc -Wall -o %e %f", it works just like the default line, it again doesn't build those files with linux libs.
It'd probably work alright if you set the command to:
C:/cygwin/bin/gcc -Wall -o %e %f
According to some documentation, Cygwin imports Windows environment variables, so even launching gcc from within Cygwin bash it might still find the wrong gcc (ie. MinGW one) due to Windows PATH environment variable. Here's a blurb from those docs:
The PATH environment variable is used by Cygwin applications as a list of directories to search for executable files to run. This environment variable is converted from Windows format (e.g. C:\Windows\system32;C:\Windows) to UNIX format (e.g., /cygdrive/c/Windows/system32:/cygdrive/c/Windows) when a Cygwin process first starts...
You might need to tinker with the linker's library search paths (ex. LD_LIBRARY_PATH) and gcc include directories too.
Related
I have installed clang 3.8 from the base repositories for both Debian Jessie and Fedora 24. When I try to compile a simple HelloWorld.cpp test program with clang++, and i pass the -fopenmp flag, in both cases i get the same error:
/usr/bin/ld: cannot find -lomp
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)
I see that if I instead pass -fopenmp=libgomp, it works. However, the Clang OpenMP website says that the OpenMP runtime is shipped with Clang 3.8. Why, then, can it not find the default libomp library? I do not see this library anywhere on my system.
There is good chances that the OpenMP development package is missing on your system.
On Ubuntu: sudo apt install libomp-dev
If you have libomp installed correctly you will need to use -fopenmp=libomp. libgomp is for gcc. You might check that clang isn't symbollically linked to gcc on your computer.
TL;DR
If you have libomp.so for llvm in somewhere like /usr/lib/llvm-12/lib make file /etc/ld.so.conf.d/libomp.conf with the line /usr/lib/llvm-12/lib in it, then run sudo ldconfig.
Intro
In my case, I had libomp-12-dev installed, but it was not in my linker's library path. See the footnote on how I found the library. There are a couple solutions in this scenario:
Add library path with ldconfig
If you want this in your default library path, consider using ldconfig [man page].
This will look for files in /etc/ld.so.conf. For me, running Ubuntu 20.04, this file only points to including files in the directory /etc/ld.so.conf.d.
$ cat /etc/ld.so.conf
include /etc/ld.so.conf.d/*.conf
As such, I made a config llvm-libomp-12 in my /etc/ld.so.conf.d directory that looks like this:
$ cat /etc/ld.so.conf.d/libomp.conf
# libomp.so for llvm
/usr/lib/llvm-12/lib
Then I asked ldconfig to update the paths with sudo ldconfig. You can add the -v flag and it will print all libraries and paths it is aware of.
Add library to environment variable
We can also direct the linker to our library using the $LD_LIBRARY_PATH environment variable
This may be advantageous if you're on a multiuser system and don't want to impact others, or if you have temporary changes to your library paths you would like to make in your shell.
See what your current $LD_LIBRARY_PATH is with echo $LD_LIBRARY_PATH. You may not have this set by default. Add paths to this variable, each delimited by a colon.
For your current shell session, simply append or prepend to your $LD_LIBRARY_PATH like this (assuming bash, zsh, or fish >v3.0):
export "$LD_LIBRARY_PATH:/path/to/lib"
Or for a more permanent change limited to your user, add the above export to your shell's config file (e.g. ~/.bashrc).
Manually specify library path(s) in compiler flags
Nice for a one-off specific library that you don't always want in your default library paths. Specify the path to the library as a flag like this:
-L/path/to/lib
For example:
clang++ -L/usr/lib/llvm-12/lib [...]
make -L/usr/lib/llvm-12/lib
Footnotes
On searching
If you don't know where a given library you need is, you can use things like find. Personally though, I used a package called mlocate that indexes files on my machine and allows you to search them.
Installing mlocate
sudo apt install mlocate
Updating the indexes
sudo updatedb
Searching for a substring
locate libomp.so
When I searched for where my libomp libraries were, I did this:
$ locate libomp.so
/usr/lib/llvm-12/lib/libomp.so
/usr/lib/llvm-12/lib/libomp.so.5
/usr/lib/x86_64-linux-gnu/libomp.so.5
Notably it seemed like clang was using the libomp.so.5 in the linux-gnu directory, but I needed it to be using the llvm library.
Environment used in this post
$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
$ uname -a
Linux bip 5.8.0-48-generic #54~20.04.1-Ubuntu SMP Sat Mar 20 13:40:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
TODO
Some notes that could be added to this question:
Confirm and list priority of env vars vs config files vs flags (does this vary between compilers and linkers?)
Ordering library paths when using multiple config files (can we prefix with numbers to ensure the order libraries are parsed?)
I have Eclipse CDT installed (juno) on my windows 7 computer
I have cygwin installed (able to manually create a makefile and create a .so)
I want to use the cygwin compiler in eclipse to create a .so
I created a new shared library project in eclipse told it to use the cygwin c++ compiler
do a ctrl-b and it creates a .dll
how do I get it to make a .so?
this is using windows 7
11:13:05 **** Build of configuration Debug for project cygwinc++ ****
make all
Building file: ../main.cpp
Invoking: Cygwin C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
cygwin warning:
MS-DOS style path detected: C:\Users\EAIGREG\workspace\cygwinc++\Debug
Preferred POSIX equivalent is: /cygdrive/c/Users/EAIGREG/workspace/cygwinc++/Debug
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building: ../main.cpp
Building target: cygwinc++.dll
Invoking: Cygwin C++ Linker
g++ -shared -o "cygwinc++.dll" ./main.o
cygwin warning:
MS-DOS style path detected: C:\Users\EAIGREG\workspace\cygwinc++\Debug
Preferred POSIX equivalent is: /cygdrive/c/Users/EAIGREG/workspace/cygwinc++/Debug
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Finished building target: cygwinc++.dll
11:13:06 Build Finished (took 390ms)
clearly this is using the wrong compiler... i know that my cygwin can create SO so how to i tell it to use the "linux" c++ compiler?
Perhaps there is a way to accomplish what I was looking for, but what I ended up doing was getting another computer running linux...
If I wanted to I could have just manually create my makefile and manually link and compile (maybe a few fancy batch files) but in the end it was just easier to have a full working eclipse environment natively in linux
My gcc compiler is at a custom location /my/path/hpgcc
I've downloaded the boost sources. Executed bootstrap.sh, but it fails because it runs with the default gcc.
Looking into it, I see that it fails at the first thing it does: building the Boost.Build engine:
gcc -o bootstrap/jam0 command.c compile.c debug.c expand.c glob.c hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c newstr.c option.c output.c parse.c pathunix.c pathvms.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c pwd.c class.c native.c md5.c w32_getreg.c modules/set.c modules/path.c modules/regex.c modules/property-set.c modules/sequence.c modules/order.c execunix.c fileunix.c
(fails because executed with the default gcc, and not my gcc version).
I've tried to change the gcc path in the user-config.jam file, but it doesn't help. Probably because the Boost.Build's build script boost_1_47_0/tools/build/v2/engine/build.sh doesn't use user-config.jam, and just uses the default locations.
Any solution?
Add the line:
using gcc : : /my/path/hpgcc ;
to user-config.jam. user-config.jam will usually be in /path/to/boost/tools/build/v2/, but you can put a custom user-config.jam or site-config.jam in any of the places listed here.
/my/path/hpgcc should be the full path to the g++ executable.
EDIT (Igor Oks) : What eventually solved the problem is that I edited boost_1_47_0/tools/build/v2/engine/build.sh to make it use my custom gcc.
We do this in our build environment by simply defining the PATH and LD_LIBRARY_PATH environment variables to pickup our desired GCC first.
This question may sound a little absurd. Facts:
I have a program written in C++.
It uses lot of in-house libs.
I don't have read permission to the libs.
So I have to build with a given tool which does have access to the lib headers and archives.
Stuck on gcc 4.3
I have a local build of gcc 4.5
I want g++ to use my local g++ instead of the old version.
Is there any way to get this done?
Use the full path of the compiler instead of invoking it without specifying the path.
Many configure scripts accept the CC environment variable:
export CC=/usr/bin/gcc44 for example. If you have a configure script, try ./configure --help to see if it's supported.
Assuming you have g++ in your ~/bin folder, could you add
export PATH=~/bin:$PATH
to your shell's .profile file (.bash_profile for bash). Then when you log in again and do which g++ it should show your local version of g++.
I'm trying to compile C/C++ code from an external source using SciTE. The SciTE has a built-in feature where it searches for the gcc compiler and libraries in the same folder. The problem occurs if I try to compile from SciTE externally. Compiling with F5 (compile and run) or CTRL-F7 (compile) results in SciTE not being able to find the compiler.
I'm wondering if there is a way (there always is) to embed the gcc compiler's path into one of SciTE's files without generally rewriting SciTE's code?
EDIT: Found a solution in Linux.
I used MinGW as an external source to compile in C and C++ code in scite.
If you do not have MinGW you can get MinGW here: http://sourceforge.net/projects/mingw/files/Installer/mingw-get-inst/
mingw may have problems if installed into directories containing spaces.
After installing MinGW add the bin directory to sysytem path environment variables.
Go to Control pannel.
System
Advanced system settings
Click on the Environment Variables tab
Add the MinGW's bin directory to the path system variables list.
Default directory: "C:\MinGW\bin"
In scite:
Open cpp.properties
Search for: cc=g++ $(ccopts) -c $(FileNameExt) -o $(FileName).o
Change the g++ part to MinGW's bin directory plus compiler exe ex:
cc=C:\MinGW\bin\g++.exe $(ccopts) -c $(FileNameExt) -o $(FileName).o
For gcc compiling change ccc=gcc.exe $(ccopts) -c $(FileNameExt) -o $(FileName).o to ccc=C:\MinGW\bin\gcc $(ccopts) -c $(FileNameExt) -o $(FileName).o
Now search for command.go.$(file.patterns.cplusplus)=./$(FileName)
Change it to command.go.$(file.patterns.cplusplus)=$(FileName).exe
For gcc compiling search for command.go.*.c=./$(FileName) and change it similarly.
Save the changes to file
Please note that you may have to change permissions in the scite folder before you will be able to save the changes to cpp.properties
Your code will now be able to compile (use shift+F7) and run(F5).
Go to options -> cpp.properties -> goto line 303 or find the following line:
cc=g++ $(ccopts) -c $(FileNameExt) -o $(FileName).o
next line will be for gcc option.
Now set full path for gcc or g++ as follows,
ccc=D:\Dev-Cpp\bin\gcc.exe $(ccopts) -c $(FileNameExt) -o $(FileName).o
In the above line D:\Dev-Cpp\bin\gcc.exe is the path for gcc on my system. You can do the similar thing by editing the path according to your own installation of gcc. Once set write a program and compile.
Note: There are other options for you to set for example the standard to use for compiling your programs.
I hope it helps.