Import C + Makefile into a linux IDE? - c

I have a project for Linux that i've been developing for some time. Basically it's a bunch of C and H files together with a directory structure and a Makefile.
Every time I need to debug something it's so painful, I need to manually search for var. definitions, structs, etc.
Is there any good IDE out there for Linux that will allow me to import those files into a "project" and that will provide code completion or at least an easy way to get my bearings in the source code?
thanks!

Eclipse with the CDT
CDT is pretty much Makefile based, just create an empty 'make' project then drop your files into it and refresh in eclipse then add your make targets.
Eclipse should pick stuff up from make output.

It depends on your definition of "good", but Emacs in connection with Cedet and AutocComplete does a good job in my opinion - but it's not too easy to get used to it.
Another IDE i've used (but not on Linux) is CodeBlocks.

There are several ways of going about this:
ctags: Most editors have ctags or etags support, which allows you to jump easily around in your source code. The tag file can be built by the makefile.
KDevelop: Version 4 is not bad, and is a more integrated IDE if standard text editors aren't your thing.
Eclipse with CDT: Eclipse is passable, and will work with C/C++ easily.
Emacs: Add CEDET (included in newer Emacs releases) for real code completion.

Related

How can I tell Netbeans I'm cross-compiling?

Please don't answer this as a "How do I cross-compile on Linux for Windows" question, I solved that part. I need some specific instruction on configuring Netbeans. Thank you.
I'm developing a set of C functions that I want to distribute as a .dll on Windows, and a .so on Linux. (This is going to be used from java as a JNI library, but that's irrelevant to the question).
Development environment is Netbeans 8.2.
I have gcc and mingw installed, and compiling my source code for both targets works.
However, I want to create NetBeans configurations "Linux-Release" and "Windows-Release", with Linux-Release using gcc to create the .so file, and Windows-Release using x86_64-w64-mingw32-gcc. So I created a Mingw tools collection that refers to the mingw versions of the C compiler:
In my project properties, I created a Windows_Debug configuration, and told it to use the Mingw tool collection:
I can use this configuration to get a working Dll. However, the output file will be put into the dist/Windows_Debug/Mingw-Linux directory (not dist/Windows_Debug/Mingw-Windows as I'd like), and it's put there with a .so extension, not .dll. I can load this file on Windows when I rename it to .dll, but this will horribly confuse anyone I want to collaborate with.
Naively messing with the CND_DLIB_EXT macro in the generated Makefiles doesn't help at all, they just get overwritten.
I guess I have to either tell Netbeans that the Mingw Tool Collection compiles to Windows, or that the Windows_* configurations compile to Windows, so Netbeans sets the correct values for CND_* and the default output Macro
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/libSMAQSJni.${CND_DLIB_EXT}
in the linker part of Project Properties works again. (Of course, as a workaround, I could just remove the variables from the macro, and replace them with appropriate constants, but I want to do this "right". I haven't found a way to tell Netbeans "this compiles to Windows" anywhere though, neither in the GUI nor in any of the config files. So, how do I do this?

Are Cmake/Autotools useful for non standard compilers?

I am working on a complex project written in C/Asm for an embedded target running on an Analog Devices DSP. The toolchain is close to gcc, but they are plenty of differences. Moreover, I am using a lot of autogeneration scripts using Jinja2 to generate header files from data extracted from a database. I also have plenty of compiler flags.
I currently wrote a Makefile from scratch. It is about 400 lines long and works pretty well. I automatically discover the sources across the directories and hold all the dependencies i.e.
a.tmpl --->jinja-->a.c--->a.o
^
a.yaml ------'
I would like to know if tools such as Cmake or Automake can be useful in my case. In other words, can I use these tools to simply the readability of Makefile?
CMake works perfectly with generated sources. Just add appropriate custom command:
add_custom_command(OUTPUT a.c
COMMAND jinja <args>
DEPENDS a.yaml)
add_executable(a a.c)

C code compilation

i want to compile a 'c' code and create an executable from my application. as of now i do it by specifying the path of my compilation .exe (c++) present in the bin folder of my Dev-Cpp folder.
it works fine but i need to pack the compiler along with the application so i wanted to know what files and folders are needed so that i can compile it directly from the application.
what are the files needed exactly i.e. headers,the compilation application, libs and what else...
any help?
If you're asking how to create and distribute a project which is able to build upon an existing compiler for its functionality, there are packages you can find which are just the compiler portion without the IDE. Minimalist GNU for Windows is such a package:
http://en.wikipedia.org/wiki/MinGW
(In fact, when the people who put together Dev-C++ wrote their integrated development environment, they get the actual compilation functionality from MinGW...which they bundled into their package for good measure. So if you were going to write an IDE of your own, you would start from the MinGW distribution...not by trying to hand-pick files out of Dev-C++.)
One issue to be sensitive to is licensing. While there are not generally any legal issues out of the box regarding distributing executables built with a system like MinGW, when you go as far as to include the compiler in your own "product", it might be tricky. Dev-C++ is under the same license as MinGW (GPL) but I'd imagine there'd be issues if it were not.
If you only need a subset of the full functionality (let's say you only compile C and not C++) there will be a lot of header files and such that you could cut out. But you have to trade off the difficulty of maintaining this sort of optimization vs. just having your program ask users to install MinGW and then tell your program where they installed it. It might take up more space and lead installation to be a two-step process...but frees you from a large number of concerns.
So that's what I would suggest: Have a setting in your program (much like Dev-C++ does) which lets people specify where the MinGW binaries are installed on their system. But let them install it independently.

Compiling open source projects

I have been trying to compile open source projects since past few months with no success. I just don't know how to go about the entire thing. Readings over the internet have not helped much.
Some come with ./Configure and a Makefile while others with only a Makefile. How to use them to generate executables (or they have some other purpose ).
My machine currently has:
Windows XP,
Mingw Compiler for C/C++,
Cygwin
Do I need any other software?
Thanks!
Edit:
Thanks for the response. Currently I am trying to compile "Null Httpd". It comes only with a makefile.
In my command line prompt I type
/directoryContainingMakeFile/mingw32-make Makefile
I get
"Nothing to be done for 'Makefile'"
:(? Am I doing it the right way?
./configure is the first thing to run, if it exists -- it checks if your system has the requirements for the project, and also allows you to set project specific settings or simply set the default values.
Next, the command make (though some projects require automake, or cmake, which are similar but more powerful utilities) takes those configurations and builds from the source code into the executable. Make isn't a compiler in itself though -- its simply used to specify how to build the project. Most projects in C use gcc, probably with many standard libraries to be linked in, in which case this should run on top of cygwin perfectly well. If it has other dependencies however, you are on your own for the most part (this gets complicated very quickly -- if this happens, its usually a less time-consuming effort to work in the OS the source was made to compile on).
After this, you should find the binaries you require in the same directory :)

How to build executable from c written source files?

There is few files with .c anf .h extensions (cmdline.c cmdline.h core.c core.h and so on) in src directory, also there is one file "MakeFile" without extension. Is there any possibility to build these source files into some executable file on Windows 7 (64bits) ? I think i need to download compilers for C or some sdks right?
Yes.
You need to:
download and install a C/C++ compiler (I recommend TDragon's distribution of MinGW ),
add the compiler to your PATH (the installer can do it for you most of the cases); verify it's done by opening cmd.exe and typing gcc -v and mingw32-make -v, both should give you half a screenful of version information if your path is set correctly,
via cmd.exe, navigate to the folder in which the Makefile resides and call mingw32-make.
From now on everything should compile automatically. If it doesn't, post the errors.
Update:
First of all, it'd be useful for you to get the MSys package. Install it and you'll have a more recent version of make (use it instead of mingw32-make from now on).
About the CreateProcess bug, it has to do with the system PATH variable being too long. You'd need to do something like this:
open cmd
execute set PATH=c:/mingw32/bin;c:/msys/1.0/bin (change the paths here to reflect your own installation if it's different)
then as before: navigate to your project's directory, run make. Everything should be smooth now if you're not missing any external libraries.
BTW- remember not to install MinGW or MSys in directories with spaces.
I am not a Windows Developer..
But still as per my knowledge. Visual Studio (i.e 2008, I guess) has the ability to read the Makefile.
Please have a look at it..and if needed change this makefile to their format..
There are many opensource product which are platform independent..and they get compiled on both OS with the just Makefile they provided.
Or else use 'cygwin'
Developer C++ works in windows but it is actually GCC code bought into Windows, Is anyone familiar about the procedure they used to convert the linux ( .sh) to executables ??
I think i need to download compilers for C or some sdks right?
A compiler certainly, but what additional libraries you may need will depend entirely on the code itself. A successful build may also depend on the intended target of the original code and makefile. The makefile may be a GNU makefile, but there are other similar but incompatible make utilities such as Borland Make and MS NMake. If it is a simple build, you may be able to avoid the makefile issue altogether and use the project management provided by an IDE such as Visual C++ 2010 Express.
If you do not know what this code is or what it does and what it needs to build, you are taking a risk building it at all. Maybe you should post a link to the original source so that you can get more specific advice on how to build it.
[EDIT]
Ok, now looking at the code you are attempting to build, it is a very simple build, so if you wanted to avoid using GNU make, then you could just add all the *.c files in the src folder to a project in your IDE and build it.
However there is one serious gotcha, it uses the BSD sockets API and Linux system headers. You will need to first port the code to Windows APIs such as WinSock (very similar to BSD Sockets), or build it under Cygwin (a sledgehammer for a nut somewhat). There may be other Linux dependencies that need sorting, I have not looked in detail, but it looks fairly simple. That said, if you did not have the first clue regarding compiling this stuff, then perhaps this is not a task you could do?
Of course compiling the code may only be half teh problem, if it was designed to run on Linux, there may be run-time dependencies that prevent it running on Windows. Again I have not looked in detail.
Also looking at the code, I would suggest some caution, this may not be the best quality code. That may be unfair, but one obvious flaw and an indication if inexperience is the lack of include guards in the headers.

Resources