Make Clion consider ".h" files as C++ - clion

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.

Related

How to hide a single header file from gcc

I am compiling a c++ project and trying to find all what all functions from ncurses.h are used throughout the project.
I was wondering if I can tell gcc to not include specifically ncurses.h?
I ended up passing -D__NCURSES_H=1 on command line. 🤷‍♂️

Mingw compiles my c code as c++. How do I prevent that?

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.

Assembler used by golang when building with and without cgo

Let's say I have a golang package, which contains some assembly code:
demopkg/
source1.go
source2.go
asm_amd64.s
If I try to build it using go build, toolchain will use go tool asm to assemble the *.s files.
But if I add Cgo to the mixture, by putting a single import "C" into any of the sources, go will switch to gcc assembler.
I can see it by executing go build -n. Calls to the /usr/local/go/pkg/tool/linux_amd64/asm from the first case get replaced by calls to gcc. Besides that, it starts complaining about broken syntax.
Is this behaviour documented, so I can rely on it for the maintaining of my package? Can I force go build to use one exact assembler?
Yes, it's in the cgo documentation
When the Go tool sees that one or more Go files use the special import
"C", it will look for other non-Go files in the directory and compile
them as part of the Go package. Any .c, .s, or .S files will be
compiled with the C compiler. Any .cc, .cpp, or .cxx files will be
compiled with the C++ compiler. Any .h, .hh, .hpp, or .hxx files will
not be compiled separately, but, if these header files are changed,
the C and C++ files will be recompiled. The default C and C++
compilers may be changed by the CC and CXX environment variables,
respectively; those environment variables may include command line
options.

Using CMake to resolve #include dependencies in an exotic language

I'm trying to use CMake as my build tool driver (I make it clear at once that I'm quite new to CMake since this my first on-my-own CMake project). My project is mainly C with some files in an exotic language I'll call here Z. These Z files must be processed by their Z compiler to produce .h and .c files.
I managed to tweak CMake handle Z compiling and dependencies between plain C files and generated Z -> .h header with
add_custom_command( ...*details omitted*... )
set_source_file_properties(*generated-.h* PROPERTIES GENERATED TRUE)
and CMake C-#include scanner does properly the rest of the job.
Now, Z files use something equivalent to C #include construct and I'd like to make profit of automatic recompilation when one of the Z-included files changes.
If a.Z includes inc.Z, I tried:
set_source_file_properties(a.Z PROPERTIES OBJECT_DEPENDS inc.Z)
but that doesn't trigger automatic recompilation of a.Z.
CMake manual says this property was introduced for this purpose and is no longer necessary for C/C++. However it is ineffective in my Z case.
If I modify my custom command as follows:
add_custom_command( ... DEPENDS inc.Z ...)
I get the desired result, but not all Z files depend on inc.Z (another one might depend on inc2.Z).
I then tried to generate dynamically the DEPENDS list with
get_source_file_property(dependencies ${filename} OBJECT_DEPENDS)
if(dependencies STREQUAL "NOTFOUND")
unset(dependencies)
else()
string(REPLACE ";" " " dependencies "${dependencies}")
endif()
add_custom_command(... DEPENDS $filename "$dependencies" ...)
and make errors out with
Make[2]: *** no rules to build target `-- content of dependencies variable --'
Note: error is the same with or without double quotes around variable substitution
I guess CMake interpreted my list of dependencies as a single (non-existent) filename and make was unable to handle that. Anyway, the files mentionned in the dependencies variable are not meant to be compiled, only to be included somewhere. They must make their way to make only as dependencies.
Which direction should I go to achieve the desired result?
Recall this is my first on-my-own CMake project and I certainly made newbie errors.
FWIW, my platform is Linux with CMake 2.8.9 (not bleeding edge but I'm only exploring) and KDevelop 4.x
Thanks for your help.

dev cpp win32 the program can't start because sqlite3.dll is missing

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).

Resources