Set compiler includes (-I) with c.vim plugin? - c

I've been setting up vim to us as my C/C++ IDE recently and have been really impressed with the c.vim plugin (found here). However, I'm working on a project that relies on a library that is not found in my system includes. When I compile manually, I just list this directory by passing g++ an include flag (e.g. g++ -I ~/lib/). Is there any way to set up c.vim to have this directory included when I use the "save and compile" ("\rc" by default) command?
Thanks!

I'd would just set $CXXFLAGS to -I~/lib, it's its job -- unless you are using the dumb makefile default configuration from mingw project, $CXXFLAGS will be recognized automagically, as long as your &makeprg still points to make and not directly to g++ or any other compiler (I don't know what c.vim does with this vim setting as I don't use it).
As I suspect you don't have any Makefile in your directory but just a monofile project, I'd prefer an extended modeline over project settings.

Related

trying to use cuda with go on windows

There are various Go libraries that rely on the cuda.h file and the cuda library (specifically ML libraries). Every time I try to install one of these libraries on Windows, I get an error saying
fatal error: cuda.h: No such file or directory
//#include <cuda.h>
I am aware of what I need to do (link the Cuda library/header files to the go library that I am trying to install), however, I am not sure how to go about doing this especially on windows. I am using GCC and not MSVC for various reasons, but even when I've tried using MSVC, I've had the same issues.
Is there some way that I can link the cuda compiler/header files directly to my Go env or do I need to manually point the go/cgo compiler to the directory holding the Cuda headers and how do I go about doing this?
I've tried asking a few of the developers who make these libraries for help but most of them are linux users so they don't really know. An exhaustive google search has really lead me nowhere so I'm asking here.
I was able to find the answer.
The windows cuda installer installs things by default into a weird path:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include
This path caused a lot of pain for the compiler as a result of the spaces in the folder names. After reinstalling Cuda into C:\CUDA\v8.0 and then appending my CFLAGS and LDFLAGS appropriately in my CGO file I was able to get things to run correctly.
For reference here are the CFLAGS and LDFLAGS that I used to get this to work:
//#cgo windows LDFLAGS:-LC:/cuda/v8.0/lib/x64
//#cgo windows CFLAGS: -IC:/cuda/v8.0/include
import "C"
This was with the github.com/chewxy/cu go library. I also appended the new flags into that library in the cgoflags.go file because the maintainer did not have version 8 or version 9 in there already. I mentioned this to him and he might update it later but for now that's what you have to do.

Bypass C errors to generate clang debugging information

TL:DR
Can you generate clang debugging information(CFGs, PDGs) when the original source file have DEPENDENCY errors from missing header files that cause compilation issues such as undeclared identifiers and unknown types? The files are syntactically correct. Is there a flag that maybe set all undeclared identifiers to INTs for debugging?
I am using Clang to analyze source code packages. Usually, I modify the makefile so clang generates debugging information using the command below
clang -emit-llvm -g -S -ferror-limit=0 -I somefile some_c_file
However, this approach is very makefile focused and if developer does not support Clang in that given build version, I have to figure out how to generate the debugging information.
This is not good for automation. For things such as OpenSSL where they include dozen of files(headers) and custom configurations for the given platform, this is not practical. I want to suppress or ignore the errors if possible since I know the build version's file under test is syntactically correct.
Thanks!
Recently I used clang-tidy for source code analysis of one of our projects. The project uses GNU compiler and we didn't wanted to move away from that. So the process that I followed was below:
1) Use bear to generate the compilation database i.e. compile_commands.json which is used by clang-tidy
2) By pass the include files that we don't want to analyze by including them as system files i.e. use --isystem for their inclusion and project specific files using -I. (If you can't change the Make files you could change the compile_commands.json by a simple find and replace)
Hope this helps

Eclipse Looking for g++ Instead of gcc

I have the opposite issue compared to most questions I see posted here, and my google-fu has run out. I'm using Eclipse Luna to work on a C project (on Ubuntu 14.04), with a makefile that I am not allowed to modify. There is no C++ in this project.
The makefile uses the $(CC) variable instead of explicitly setting a compiler, and there is no CC= or CC?= set to anything within the makefile.
Running make in terminal works without issue to compile my project, however in Eclipse it says Program "g++" not found in PATH.
I set up eclipse to use make as the build command and set the toolchain to be "Cross GCC". I don't have a single c++ file in my project, so why would it be looking for g++ as the default compiler? Did I miss some detail to set this up, such as adding CC as a variable set to something within eclipse?
The issue was that the CC environment variable was never properly being set anywhere so Eclipse would default it to g++. In order to fix this follow the below steps:
Open the Project's Properties
Click on the C/C++ Build option on the left hand side
Uncheck "Use default build command"
Make sure you have a valid build command in the box usually just make will do unless you're using other options.
Click on the button named 'Variables..."
Locate CC and update the value to what it should be.
Here's the documentation where I located this: help.eclipse.org/luna
According to this forum post another option is to actually update the command being passed inside of that 'build command' box to make CC = gcc, however I've never tested this.

How do I use custom assembler for clang?

I've compiled clang to use it as a cross compiler for ARM (by configuring it with ./configure --target=armv7l-unknown-linux-gnueabihf ), but when I try to compile any C code, it tries to use /usr/bin/as. I already have binutils compiled for ARM, and they are in a separate directory. How do I direct clang (or llvm) to use the assembler that I specify?
try passing the --host option to configure which will cause all the cc ar etc utilities to prefix with armv7l-unknown-linux-gnueabihf-
eg:
./configure --host=armv7l-unknown-linux-gnueabihf --build=i686-unknown-linux-gnu
Since you are using configure with hopefully autotools take a look at:
automake Cross compiling
I've always had trouble configuring from the source directory using ./configure and gave up in the end. These days I always configure from a separate directory i.e. ..//configure although I'm told it's recommended to use an absolute path for configure.
Your ARM binutils should be installed in the same prefix you're using for clang and make sure that they're in the path when you configure & build clang - i.e. PATH=/some/prefix/bin:$PATH; /configure --target=armv7l-unknown-linux-gnueabihf. If you're keeping them in separate directories for packaging purposes then make install DESTDIR= should help.
I don't generally build clang but the buildscripts I use for devkitARM might be helpful - http://sourceforge.net/p/devkitpro/buildscripts/ci/c372699fc7b4de90eb044314ce5bed04db640291/tree/

A couple of Eclipse C/C++ questions

I've been using VS2008/2010 for a while and I'm going to learn using Eclipse Helions for C/C++ development (mainly C).
I am abit confused about libraries and includes though.
1) How do you properly include winsock2.h for example? I've tried this:
#ifndef CONFIG_H_
#define CONFIG_H_
/* Windows-Build */
#if defined(WIN32) || defined(_WIN32)
#include <winsock2.h>
#endif
SOCKET sock;
#endif /* CONFIG_H_ */
But the compiler dosn't recognise SOCKET. Do you have to manually add the full path to winsock2 somewhere?
2) What about ws2_32.lib? Where do you include that in Eclipse? Do you have to add a path as well?
3) Having used VS mostly I'm new to makefiles. How do you include custom makefiles? Is there a good guide for starting with makefiles?
4) Is there a intellisense like in VS?
That's what I can figure out right now.
Thanks!
EDIT:
In response to the first answer:
Building target: Filesharing_core.dll
Invoking: Cygwin C Linker
gcc -L"C:\cygwin\lib\w32api" -shared -o"Filesharing_core.dll" ./src/test.o -llibws2_32.a
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../../i686-pc-cygwin/bin/ld: cannot find -llibws2_32.a
collect2: ld returned 1 exit status
make: *** [Filesharing_core.dll] Error 1
First off, cygwin will usually use GCC as it's compiler. That means that there's no special windows support that you'll find in the VS compiler and editor. Be prepared to get your hands dirty.
Keep in mind that my CDT version is a bit old and I don't have Cygwin installed so some of the things below might not be accurate. Also all the compiler options that I mention are detailled in the gcc manual.
1) In your sample, nobody is defining WIN32 or _WIN32 (I don't think GCC is going to do that for you but do check). To fix that, you'll have to include the windows.h header which (I think) will take care of definning the correct macros. You could also use the -D compiler switch (configurable in your makefile or through the eclipse menus).
If you encounter missing include errors once you've fixed the defines, I believe that the windows headers are located in the C:\cygwin\usr\include\w32api folder. To add that to your include path, simply open your project properties and navigate to C/C++ General > Paths and Symbols. Add the path to the GNU C group in the Includes tabs. Depending on how you configured your project, this might have already been done for you.
If you're building with your own makefile, you should still do the previous step because it will allow the indexer to find and parse those headers. To tell the compiler about the include folder, use the -I switch.
2) I'm going to guess that ws2_32.lib is the lib file for winsock2. If this is the case, I'm not entirely sure who's responsible for building it (is there a .dll you can use instead?). You might want to check your c:\cygwin\usr\lib folder or the c:\cygwin\usr\local\lib.
If you're using a managed project (eclipse builds the makefile for you) then go to your project properties and navigate to C/C++ Build > Settings. In the Tool Settings tab, go to the libraries item in the linker section. Just add the name of the lib file and the folder in the appropriate boxes.
In your own makefile you'll want to use the -l compiler switch to specify a library and the -L compiler switch to specify a search path.
3) A good place to get started with makefiles would be the GNU make manual.
One detail about running a Makefile on Windows: make sure to use the shell provided by Cygwin or MinGW. Otherwise, commands like rm won't be defined and it'll make your life very difficult.
You might also want to consider CMake. It's easier to use and scales better to larger projects.
To use a hand-made makefile in your project, just create an new Makefile project and dump your Makefile file in the root of your project folder. That's it.
4) Yes there is but it's not called intellisense. Just hit CTRL+Space anywhere in your source code to bring it up.
Other fun tools can be found in the right-click menu. My personal favorites include CTRL+SHIFT+R to find and open a file, CTRL+SHIFT+T to find and open a type\variable\function\define and CTRL+O to find and goto a type\variable\function\define within the opened file.
The indexer can go a little crazy sometimes (mostly when parsing C++ code). You can modify its behaviour by going in the Windows > Preferences menu at the top and navigating to the C/C++ > Indexer item.
I hope this helps.

Resources