When creating a new C-Win32 project in Mingw (gcc) I accidentally added a cpp file as one source file to the other C files.
Now Mingw compiles my c code as c++. I found out by testing that __cplusplus returns true.
I've looked all the project settings in my Codeblock IDE and compared then to other projects that compile as C.
How do I tell Codeblocks/Mingw/GCC to compile it as C source and turn off __cplusplus?
First change the file's extension from .cpp to .c. To do this:
Close file.cpp in the Code::Blocks editor, if it is open.
Right click on file.cpp in the projectname -> Sources
tree-view.
From the menu select Rename file... and name it file.c
That should be a sufficient hint to Code::Blocks that you want the
file compiled with the C compiler and not the C++ compiler, but it isn't.
When you add file.cpp to a project, C::B registers it for compiling
with the C++ compiler and it sticks to that even if you rename the file
to file.c.
To make it change its mind you must also do this:
After renaming the file to file.c, once again right-click on it in the project tree-view
and this time choose Properties...
In the Properties dialog, click the Advanced tab.
Change the value of Compiler variable from CPP to CC, then OK out.
Now the file will be compiled with the C compiler.
Related
I'm trying to interface BME680 gas sensor module with AVR controller (Atmega644p to be specific) using Atmel Studio in Windows platform.
The BME680 does come with example functions multiple .h,.c files for configuration and one .a (static library). .h and .c files are calling some functions from static library as well, so we need to include all available .h, .c and .a files.
.a file was new to me and after basic web search I concluded that .a files are for Unix as .lib files are in Windows.
So can you find me a way to either:
convert my in hand .a file to .lib file?
or
to add .a file in Atmel studio in Windows platform?
Any help will be highly appreciated.
I did try to include .a file using following steps:
In Project=>Properties
click on the Toolchain tab Under XC8 Linker
click on Libraries In the Libraries (-l) window
click the "+" sign and add "libalgobsec" to the list In the Library
search path (-L) window
click on the "+" sign In the "Add Library search path (-L) dialog
click on the "..." button In the file dialog, navigate to the folder
that contains libalgobsec.a
Click okay.
Under Project Properties => XC8 Linker => Miscellaneous => Other
Objects, add: -u _fstat -u _read -u _write
But it gives this error: Compilation Error.
After 2 months of experiments, coordination with BOSCH and everything, here is the conclusion.
Pre-compiled library is only compatible with AVR controllers having Boot Memory of 256 Kbytes, and only following 4 controllers make it to list:
ATmega2561
ATmega2564RFR2
ATmega2560
ATmega256RFR2
So if you try to compile libalgobsec.a available in BSEC software for Atmega controllers with any other controller than mentioned above (in my case Atmega644P), it simply doesn't compile.
I had some code that wasn't working until I added extern "C" before the name of a function, even though I was compiling using gcc. The file's name did, however, end in ".cpp".
Is it possible for gcc to name mangle? Did it intelligently pick up the file extension ".cpp"?
The gcc compiler driver looks at the file extension. If it is .cpp (or .cc, .C and a few more), the file is compiled as a C++ file:
Compiling C++ Programs
Is there a way to make CLion consider single files with ".h" extension as C++ by default and not C?
If they are not included in the CMake script, and there is no corresponding ".cc" file, it consideres them as C by default for the syntax highlighing.
In current 2018.1 version it should be treated properly as C++, one limitation is: if there is no C++ files in the configuration at all, then C will be selected.
I am using dev c++ IDE which used ming gcc(i am not sure of it)
I wanted to use sqlite3 in my win32 c application
I downloaded sqlite3.dll and sqlite3.dev and used dlltool to create a .a file like libsqlite3.a and pasted in the lib folder of dev cpp and added this path in the project options -> parameters
i copied the header file sqlite3.h into the include folder(which i got from another website - http://www.opensource.apple.com/source/SQLite/SQLite-74/derived_source/sqlite3.h)
i executed the program and got the message 'the program can't start because sqlite3.dll is missing in your computer'
so i copied the sqlite3.dll into my working directory and then it worked
BUT
How to make the sqlite.* static while compiling?
I mean i thought by including the libsqlite3.a, the final exe will not be dependent of any external dll's.
So i want to know how to compile in a way that i will not be needing a dll and by doing so it makes my windows program standalone.
do i have a create a .lib file instead of .a file?
EDIT after answers and comments:
Besides, the devpak is working fine... yet i wanted to know how to include files to project or to create .a files so i am trying this way because if some components do not provide devpak then this will be the way we need to compile.. isn't it?
EDIT to show what i have done after the answer by CL and the two comments
This is how i have added the sqlite.c to project list
Here is the compile log
Compiler: Default compiler
Building Makefile:
"C:\Users\jayapalc\Documents\test-sqlite\Makefile.win"
Executing make...
make.exe -f "C:\Users\jayapalc\Documents\test-sqlite\Makefile.win" all
g++.exe -c sqlite3.c -o sqlite3.o -I"lib/gcc/mingw32/3.4.2/include"
-I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"
sqlite3.c: In function `void strftimeFunc(sqlite3_context*, int,
sqlite3_value**)':
sqlite3.c:14727: error: invalid conversion from void*' tochar*'
The files i got in sqlite.org/sqlite-amalgamation-3071502.zip are
shell.c, sqlite3.h, sqlite3.c, sqlite3ext.h and i saw in other discussions that shell.c is not needed...
Besides, people were talking about gcc and g++... .
Apart from updating Dev-C++ itself, try this to compile sqlite.c as a C file:
Go to Project >> Project Options >> Files.
Find the C file we're talking about. Untick "Compile file as C++".
This should inform Dev-C++ that it should invoke gcc.exe, and not g++.exe.
If you don't want to compile sqlite yourself by adding it to your project, you can try passing the -static flag to GCC/G++ to force it to link libsqlite.a statically.
Just include the sqlite3.c file in your project.
You need only this filed, and it must be compiled as C, not C++.
Apparently, Dev-C++ does not allow mixing C and C++ source files in one project.
Instead, you could try to compile sqlite3.c as C and then include the generated .o file into the C++ project (on the Linker page).
I have an Objective-C/Cocoa project that incorporates a static library. That static library has some object files that have C++ in them.
I've found that if the project that I'm using the library in contains no other C++ in it, the link fails (can't link new/delete/etc). But simply adding a single (empty) .cpp file to the project causes the link to succeed.
In practice, what happens is that the build will invoke g++ instead of gcc when there is any cpp, which succeeds. No other difference in the build is apparent to me.
Is there an explicit switch I can use to link in this library without using the dummy cpp file in the project?
(This is mostly a curiosity question-- it's not the end of the world to put in one empty file. :) )
Thanks.
try to link libstdc++
gcc main.c -lstdc++
or in Xcode:
Project->Edit Project Settings
To the config section "Other Linker Flags", add -lstdc++.