Settings GCC (ARM-Linux) in Eclipse Mars for 'C project - c

I am experimenting with cross compiling for ARM-Linux under Windows using Eclipse-Mars. My set-up is as follows:
Win10 x64
Eclipse Mars.2 Release (4.5.2)
GNU Toolchain for RaspberryPi (SysGCC)
Target platform: RaspberryPi2 running Raspian
Source project in 'C (not C++) using Linux Threads (pthreads)
I have knocked up a small 'C project using 'pthreads' which compiles under Eclipse and runs successfully on the Pi.
My problem is that Eclipse shows a number of errors in its Problems TAB to do with Linux's threads:
Type 'pthread_cond_t' could not be resolved
Type 'pthread_mutex_t' could not be resolved
Type 'pthread_t' could not be resolved
I have Eclipse as:
Cross GCC Compiler settings to use g++ with -std=c++11 -O0 -g3 -Wall -c -fmessage-length=0.
Cross G++ Compiler settings to use g++ with -std=c++11 -O0 -g3 -Wall -c -fmessage-length=0.
In other words both are the same.
If I rename my source files from foo.c to foo.cpp and recompile, then the Eclipse errors disappear!!!
This implies that Eclipse's C++ settings are correct, but its 'C settings are not.
Can anybody suggest anything for me to try?

g++ ist a C++ compiler, so you might try to use other settings for the Cross GCC Compiler, eg. gcc.
Also make sure you are linking the pthread library.

Related

Compile C for Windows with MinGW

I installed the latest version of MinGW and trying to compile the project:
\MinGW\bin\gcc.exe -O3 -flto -Wall -msse src/*.c -o noname -lm -lpthread
But nothing happens. No errors, no exe files, nothing.
I am not familiar with Windows in terms of compilation.
This is a simple console application that is compilable on Ubuntu without problems with the same command.
What I am doing wrong?

Force mac to use GCC, not clang

I have a program written on Linux in GNU C. The program compiles with GCC. I have an install shell script,
gcc -o program program.c -Wall -pedantic -std=gnu11 -lm -fopenmp
which works greatly.
The problem is with Mac. For some reason, Mac sees gcc and instead uses clang even though GCC is installed and install.sh explicitly says gcc. clang doesn't work with omp.h The problem is that clang can't use omp.h and solutions offered http://releases.llvm.org/3.7.0/tools/clang/docs/ReleaseNotes.html#openmp-support don't work, and omp.h may not work in mac at all Enable OpenMP support in clang in Mac OS X (sierra)
I never use macs, and because of this nonsense I never plan to. However, some people using my program want to use Mac, so I have to deal with this.
I've tried various shell script modifications, but none of them work, mac insists on using clang and won't use gcc
I need to do one of two things which I don't know how to do:
1) force Mac to use gcc (which it refuses to do now)
2) get clang to use omp.h in mac (which from other answers on Stack Overflow, looks impossible)
Your second option (get clang to use omp.h) is not impossible (any more). From my answer here:
Try using Homebrew's llvm:
brew install llvm
You then have all the llvm binaries in /usr/local/opt/llvm/bin. To compile the OpenMP Hello World program, for example, type
/usr/local/opt/llvm/bin/clang -fopenmp -L/usr/local/opt/llvm/lib omp_hello.c -o hello
You might also have to set the CPPFLAGS with -I/usr/local/opt/llvm/include.

Netbeans: How do I switch between c and c++ compiler?

I'm using NetBeans IDE 8.0.2. When I set up a project I choose the option for c/c++ application.
However, when I compile my code it appears to be running a c++ compiler
(g++ -c -g -std=c++11 -MMD -MP -MF)
instead of a c compiler. When I go to "Project Properties" under "Build" I see I can set options for a "c compiler" "c++ compiler" and "FORTRAN Compiler".
However I don't see how I am supposed to select among these as to switch the code from compiling in c++ to compiling in c (with the settings specified on the "c compiler" tab") instead of c++.
From what I could gather online, Netbeans selects the compiler by file type, not project.
So you need to remove your main.cpp and add a main.c instead (cf Adding New Files from the tutorial).

Why gcc doesn't recognize -rdynamic option?

I got a gcc compilation error:
gcc-4.9: error: unrecognized command line option '-rdynamic'
and I tested compilation with -rdynamic in some environments. While I used the same version of gcc (4.9.2), in some environments gcc worked well, but others (e.g. Homebrew gcc 4.9.2_1, cygwin 64bit) not. What makes the difference?
-rdynamic passes the flag -export-dynamic to ELF linker, on targets that support it.
Executable formats in OS X and Windows are not ELF, thus the option -rdynamic is not supported building for these operating systems.

C Hello world: Code Blocks IDE, MinGW C compiler on windows

I can't get Code Blocks IDE to compile the hello world C program it creates when you create a new C project. I've installed MinGW and it was recognised by the IDE. But when I try to build I get the following output:
-------------- Build: Debug in TestC3 (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -Wall -g -c
C:\Users\jody\codeblocks\testc3\TestC3\main.c -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\TestC3.exe obj\Debug\main.o Execution
of 'mingw32-g++.exe -o bin\Debug\TestC3.exe obj\Debug\main.o' in
'C:\Users\jody\codeblocks\testc3\TestC3' failed.
Why is it trying to run mingw32-g++.exe as well as mingw32-gcc.exe? (And if it shouldn't be doing this, how can I configure it not to?)
The mingw32-gcc.exe step is the compile step. The mingw32-g++.exe is the link step. This
is the correct sequence and will work if your mingw32 installation is "normal" and correct - where "normal" means
you have installed the C++ as well as the C tools.
The link step is failing for you because mingw32-g++.exe cannot be executed, most likely because
it does not exist on your PATH. Try running mingw32-g++.exe at the command prompt to check.
Look in the directory where mingw32-gcc.exe resides to see if mingw32-g++.exe is also there.
If your mingw32 installation has got broken somehow I suggest you uninstall and reinstall.
If you have intentionally installed only the C tools then that will explain what you are
seeing, and it is easily fixed:
Both mingw32-gcc.exe and mingw32-g++.exe are just tool driver programs. When invoked
with compilation options for .c files, mingw32-gcc.exe invokes the C compiler. When invoked
with compilation options for .cpp|cxx|... files, mingw32-g++.exe invokes the C++ compiler. If
either of them is invoked with linkage options then it invokes the linker.
Codeblocks by default configures mingw32-g++.exe to invoke the linker because it will do equally
well for C projects, C++ projects and C/C++ projects, and it assumes you have the full C/C++ toolchain.
If you have not installed C++ tools and only want to build C, then you can use mingw32-gcc.exe
to invoke both the C compiler and the linker. To configure this in the CodeBlocks IDE:
Navigate Settings -> Compiler
Ensure that the Selected Compiler is GNU GCC
Tab to Toolchain executables
Change Linker for dynamic libs from mingw32-g++.exe to mingw32-gcc.exe
OK out of Settings and rebuild your project.
Firstly uninstall the codeblocks if you can't get something right. Move to codeblocks official site to download its minw.exe version so that you have a proper compiler for all of your C programs.
After installing go to Setting>Compiler>GNU GCC compiler.
Move to Toolchain Executables>.
Now set Compilers Installation Directory. Most probably it's C:\Program Files\CodeBlocks\MinGW\bin. Now you have to select and locate your C compiler as it is in the above mentioned directory.
After that rebulid and run your program.
It may occur because compiler installation directory path is wrong.to fix it
settings -> compiler -> toolchain executables. now set compiler directory to compiler folder. it must be in CodeBlocks folder if you downloaded CodeBlocks compiler integrated version(ex: C:\Program Files\CodeBlocks\MinGW). else you need browse to location where compiler is installed
if you can't find compiler then uninstall codeblocks and download again . but this time make sure you downloaded one which has "mingw" in name for windows.

Resources