Compiling code using gcc and SciTE? - linux

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.

Related

How to create pdf file in centos by using libharu

I'm trying to generate pdf file by using libharu library but i have compiled the code its creates objective file while run that executable file its giving
error like :undefined reference 'print_grid'
first i export the path:
export PATH="$PATH:/usr/local/lib/libhpdf.so"
and compiled
gcc -c text_demo.c -o text_demo.o
gcc text_demo.o -L"/usr/loca/lib" -lhpdf -o "text_demo.exe"
Try this:
1) Make sure you've actually installed libhpdf.so into /usr/local/lib
2) Compile and link: gcc -Wall -g text_demo.c -L/usr/local/lib -lhpdf -o text_demo
Note that you do not need "exe", you do not need the extraneous quote marks.
Also note that $PATH has nothing to do your your shared library path. That's for Windows; Linux uses $LD_LIBRARY_PATH.
3) Type ldd text_demo
This checks any runtime dependencies
4) Finally, try running your program: ./text_demo
5) Please copy/paste any EXACT error messages during your build, ldd or execute.
You need to install libharu and libharu-devel package
Please find apperopriate pakage from here for centos 5 or cent os 6
http://pkgs.org/search/libharu
And then compile your source code

Compiling my C program with my customized library (.h) using Linux

Hi team,
I have three files which I need to compile for testing, btw im using CentOS linux.
source_code.c
library.h
library.c
how do I put the library.h in the gcc library, so I can use it?
how do I compile the source_code.c to use that library?
Thank you very much.
This is basic knowledge of your tools, but you can do this:
#include "library.h" in the include section of the library.c code (at top of the file).
gcc source_code.c library.c in the linux terminal will link and compile both source_code.c and library.c. This will generate an executable named "a.out" (if there were no compilation problems). You can change its name, by adding the option -o name to the gcc command (gcc source_code.c library.c -o mycode will generate an executable named "mycode").
If you really need a library that will be used by a lot of other programs, you can look for "shared libraries", but I think that you are asking for a basic thing.
You dont need this library.h while building and executable (with gcc) as you should have specified the exact location of the library in the source file. All you need to do is gcc sourcefile1.c sourcefile2.c -o exename

How can I build C source with Windows Geany via cygwin call?

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.

MPI - error loading shared libraries

The problem I faced has been solved here:
Loading shared library in open-mpi/ mpi-run
I know not how, setting LD_LIBRARY_PATH or specifying -x LD_LIBRARY_PATH fixes the problem, when my installation itself specifies the necessary -L arguments. My installation is in ~/mpi/
I have also included my compile-link configs.
$ mpic++ -showme:version
mpic++: Open MPI 1.6.3 (Language: C++)
$ mpic++ -showme
g++ -I/home/vigneshwaren/mpi/include -pthread -L/home/vigneshwaren/mpi/lib
-lmpi_cxx -lmpi -ldl -lm -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl
$ mpic++ -showme:libdirs
/home/vigneshwaren/mpi/lib
$ mpic++ -showme:libs
mpi_cxx mpi dl m rt nsl util m dl % Notice mpi_cxx here %
When I compiled with mpic++ <file> and ran with mpirun a.out I got a (shared library) linker error
error while loading shared libraries: libmpi_cxx.so.1:
cannot open shared object file: No such file or directory
The error has been fixed by setting LD_LIBRARY_PATH. The question is how and why? What am i missing? Why is LD_LIBRARY_PATH required when my installation looks just fine.
libdl, libm, librt, libnsl and libutil are all essential system-wide libraries and they come as part of the very basic OS installation. libmpi and libmpi_cxx are part of the Open MPI installation and in your case are located in a non-standard location that must be explicitly included in the linker search path LD_LIBRARY_PATH.
It is possible to modify the configuration of the Open MPI compiler wrappers and make them pass the -rpath option to the linker. -rpath takes a library path and appends its to a list, stored inside the executable file, which tells the runtime link editor (a.k.a. the dynamic linker) where to search for libraries before it consults the LD_LIBRARY_PATH variable. For example, in your case the following option would suffice:
-Wl,-rpath,/home/vigneshwaren/mpi/lib
This would embed the path to the Open MPI libraries inside the executable and it would not matter if that path is part of LD_LIBRARY_PATH at run time or not.
To make the corresponding wrapper add that option to the list of compiler flags, you would have to modify the mpiXX-wrapper-data.txt file (where XX is cc, c++, CC, f90, etc.), located in mpi/share/openmpi/. For example, to make mpicc pass the option, you would have to modify /home/vigneshwaren/mpi/share/openmpi/mpicc-wrapper-data.txt and add the following to the line that starts with linker_flags=:
linker_flags= ... -Wl,-rpath,${prefix}/lib
${prefix} is automatically expanded by the wrapper to the current Open MPI installation path.
In my case, I just simply appends
export LD_LIBRARY_PATH=/PATH_TO_openmpi-version/lib:$LD_LIBRARY_PATH
For example
export LD_LIBRARY_PATH=/usr/local/openmpi-1.8.1/lib:$LD_LIBRARY_PATH
into $HOME/.bashrc file and then source it to active again source $HOME/.bashrc.
I installed mpich 3.2 using the following command on Ubuntu.
sudo apt-get install mpich
When I tried to run the mpi process using mpiexec, I got the same error.
/home/node1/examples/.libs/lt-cpi: error while loading shared libraries: libmpi.so.0: cannot open shared object file: No such file or directory
Configuring LD_LIBRARY_PATH didn't fix my problem.
I did a search for the file 'libmpi.so.0' on my machine but couldn't find it. Took me some time to figure out that 'libmpi.so.0' file is named as 'libmpi.so' on my machine. So I renamed it to 'libmpi.so.0'.
It solved my problem!
If you are having the same problem and you installed the library through apt-get, then do the following.
The file 'libmpi.so' should be in the location '/usr/lib/'. Rename the file to 'libmpi.so.0'
mv /usr/lib/libmpi.so /usr/lib/libmpi.so.0
After that MPI jobs should run without any problem.
If 'libmpi.so' is not found in '/usr/lib', you can get its location using the following command.
whereis libmpi.so
first, run this command
$ sudo apt-get install libcr-dev
if still have this problem then configure LD_LIBRARY_PATH like this:
export LD_LIBRARY_PATH=/usr/local/mpich-3.2.1/lib:$LD_LIBRARY_PATH
then add it to ~/.bashrc before this line:
[ -z "$PS1" ] && return
Simply running
$ ldconfig
appears to me as a better way to solve the problem (taken from a comment on this question). In particular, since it avoids misuse of the LD_LIBRARY_PATH environment variable. See here and here, for why I believe it's misused to solve the problem at hand.

How to install boost on Linux with custom location of gcc?

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.

Resources