How to get GCC linker command? - command-line

How can I get the command line GCC uses to invoke ld?
I have a problem for an AVR target where GCC apparently adds a linker option which I am trying to override, so I would like to look at the exact options GCC uses for ld.

Use gcc -v to see what commands it runs. As in,
gcc -v -o hello hello.c
This will print a lot of output, including the linker command. The actual output depends on the platform, but the linking command should be near the end. Alternatively, use
gcc -### -o hello hello.c
This is like -v, but does not actually run any commands and quotes the options.
Another option is
gcc -dumpspecs
Look for the entry for link.
The above command line flags are listed in gcc --help and explained on the man page. Here's GCC documentation for the spec files.

Related

/bin/sh: mpic++ command not found in Eclipse for Parallel Application Developers

I'm trying to use Eclipse for Parallel Application Developers to do some MPI stuff but I can't get the program to compile. Below is the error I'm getting in the console:
Description Resource Path Location Type
/bin/sh: mpic++: command not found prog C/C++ Problem
I use mpic++ from the command line (bash shell) to successfully compile programs. When I run the command using bourne shell I get an error.
/bin/sh mpic++
/usr/local/bin/mpic++: /usr/local/bin/mpic++: cannot execute binary file
When I use sudo I still get the same error. But when I first change to the bourne shell then run the mpic++ command it works.
/bin/sh
sh-3.2$ mpic++
clang: error: no input files
I've been looking at ways to change the shell used by eclipse so I can use the bash shell because I can call mpic++ without any problems. I've also tried launching eclipse with sudo but that didn't work.
I have compiled mpi in eclipse successfully. Please follow the steps:
In terminal type:
$ which mpicxx
/usr/local/bin/mpicxx
You should get the mpicxx binary path as result. I have my mpicxx in /usr/local/bin/ directory.
In eclipse, go to project properties:
Set GCC C Compiler as: /usr/local/bin/mpicxx
Also set GCC C+ Compiler as: /usr/local/bin/mpicxx
Set MacOS X C++ Linker as: /usr/local/bin/mpicxx. Also set All options as -L/usr/local/lib

using C++11 in Mex with g++ 4.8 in linux

I'm trying to call a function I wrote in C++ 11 from a mex script. The C++ code requires -std=c++11, and runs fine from the terminal.
Here's g++ -v output: gcc version 4.8.2 20140120 (Red Hat 4.8.2-15) (GCC)
I have Matlab 2013a for Red Hat.
When I first tried calling mex filename.cpp from matlab console I got:
This file requires compiler and library support for the ISO C++ 2011
standard. This support is currently experimental, and must be enabled
with the -std=c++11 or -std=gnu++11 compiler options.
So, I went into the /usr/local/MATLAB/R2013a/bin/mexopts.sh file that matlab uses to get compler options and added -std=c++11. Now I get:
cc1plus: error: unrecognized command line option "-std=c++11"
The full command gotten from mex -v filename.cpp is:
g++ -c -I/usr/local/MATLAB/R2013a/extern/include -I/usr/local/MATLAB/R2013a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -std=c++11 -DMX_COMPAT_32 -O -DNDEBUG "mexMorph.cpp"
So, how can I get this to compile properly?
Try
mex CXXFLAGS="\$CXXFLAGS -std=c++11" simple_example.cpp
Alteratively build your mex-file without directly running Matlab such as using CMake like the following github repo : mex-it
My testing indicates that -ansi and -std=c++11 do conflict, as another responder has speculated. You could edit your mex options file (e.g. ~/.matlab/R2014a/mex_C++_glnxa64.xml in my setup) and remove -ansi.
Also note that mex accepts a -v flag, which dumps a lot of useful debugging info.
It doesn't make sense, but apparently using -std=c++0x will work. I think matlab does some checking beforehand, and since it doesn't support 4.8 officially it doesn't accept it even though the compiler would.
Can anyone back me up on this?

Eclipse not finding gcc?

I did a fresh install of my computer, I installed a new Eclipse and imported a program into my workspace. The program was working fine before but now I get this message when I try to compile
Program "gcc -std=gnu99" not found in PATH
I checked if gcc is on my PATH variable and it is
user#computer:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/local/cuda-5.5/bin
and
user#computer:~$ which gcc
/usr/bin/gcc
Any idea what the problem is?
It appears to be looking for an executable named "gcc -std=gnu99", which of course doesn't exist.
I don't know Eclipse very well, but presumably you have to specify the command name gcc and the argument(s) -std=gnu99 separately.
This question discusses setting gcc options in Eclipse.
From that and my own brief experiments, compiler options are set for each project. After selecting a project, follow this sequence of menus:
Project --> Properties -->C/C++ Build --> Settings --> GCC C compiler
In my installation, I have:
Command: gcc
All options: -O0 -g3 -Wall -c -fmessage-length=0
If you have "-std=gnu99" in the "Command" setting, delete it and add it to the "All options" setting.
This is for Eclipse 3.5.2 running on Debian; the menu hierarchy might be different on yours.
If that's not it, you might also want to check your environment variables:
$ env | grep gnu99

setting breakpoints in gdb-many-window no visual cursor

I'm using emacs to single step a assembly executable, but i have a odd problem.
in gdb when i use "break main" it give's me the message
"Breakpoint at 0xDDDDDD"
but no visual cursor, when i look at my breakpoints list i see in the "What" column the message "main". But when i use
"break main.asm:55"
i see the visual cursor.
compile process:
nasm -g -f elf -l main.lst main.asm
gcc -g -m32 -o main main.o
ive also tried to use "file program_name" in gdb. Same result.
How can i fix this that when i typ break main i can see the visual cursor?
Thanks
I fixed it by using an older version of nasm
>nasm --version
>NASM version 2.07 compiled on Nov 5 2009

GCC C++ Linker section on FC13

I am trying to get OpenGL and Glut running on Eclipse Linux FC13.
After spending two days on it, I admit that help is needed. On FC13 Eclipse, I see
/usr/include/GL and /usr/include/SDL -- so the libs are there. I started Eclipse, and then tried to run a simple program on it, just like suggested here. However, two things were missing in those steps:
Callisto could not be installed --
nothing was found from the
repository
GCC C++ Linker is not found anywhere
for Eclipse 3.5.2.
When trying to run the program, I see this error:
Program does not exist
and sometimes
Binary not found
If I just run the "hello world" it works, but otherwise, those errors happen every time I try to include glut gl or sdl commands.
Here is an excerpt from the compiler error:
make all
g++ -O2 -g -Wall -fmessage-length=0 -c -o tw.o tw.cpp
tw.cpp: In function ‘void main_loop_function()’:
g++ -o tw tw.o
Yes, apparently the compiler is not able to see the glu, gl, sdl and glut libraries.
Some suggestion on how to fix?
You have to tell the compiler that your program uses additional libraries.
Use the -l argument
g++ -O2 -g -Wall -fmessage-length=0 -lglut -lGL -lGLU -lX11 -c -o tw.o tw.cpp
This should help against unsatisfied link errors.
You can set these in the properties of your Project.
Properties->c/c++ Build->Settings->Tool Settings->Linker
Check if the compiler is able to find the appropriate header files or not. If not, you are sure to get compiler errors. Try using the -I option to set the appropriate paths.
Once you've fixed that, check if there are any linker errors (undefined symbols/references or the sort). If you do: Try to set the library paths using the -L option and ask the compiler to link in the specific libraries by using the -l option. Note that the latter expects something like -lmath where in reality the library being linked in is actually called libmath.so or libmath.a (as the case may be).