In Eclipse, is there a way for, when I save a code file, to compile the object file for the file saved, and then link them together when I go to run or debug? This is with C++ on Linux with GCC.
I don't think so. In Eclipse CDT build process is started explicitly. I think that "Build automatically" option is used for Java and other languages which Eclipse knows how to build. C++ projects are usually built using some kind of make utility. You can customize your make file to set different build targets to improve performance and reduce build/compile times.
Related
I am a student studying statistic.
And my C++ teacher asked us to submit project always by code::block.
However, I am more likely to work with mac os.
And code::blocks not running good with mac.
Is that possible to convert Xcode/Visual studio project to code::block
You need to keep in mind that code::blocks or XCode are IDEs (Integrated Development Environments) which means basically they are text editors. What you need to build a program is a compiled and an IDE usually comes with a compiler bundled with it. What an IDE usually does is keep all you files together and add some info like compiler switches and so on.
This job is usually handled by a separate program, the build tool. The make program is probably the oldest of these programs and you need to have an idea of how they work.
To get to your question you can build your program with whatever editor/IDE you want, then you may need to get your .cpp files and import them in another one.
I want to separate my IAR Embedded Workbench workspace into several projects. Currently we have the OS and other code in the same project as the main application but I want the OS and other external code to be static libraries which my application depends on.
I know how to create a static library project and how to add is as a dependency for my executable, but my problem is with the compilation process. It doesn't seem like IAR understands that it must compile the library before the executable. When the library doesn't exist I get an error saying that the file is missing, but it's even worse when the library was compiled once before but some file inside changed. Then the executable compiles without any errors but it uses the OLD library!
Is it possible to make IAR build the static library on its own when it changes? And how about when I have several static libraries and more dependencies?
I had an idea to use a pre-build event, but I was wondering if there's anything out of the box for this situation, and if not what is the best solution.
We're currently using IAR 6, but will probably move to 7 soon.
I talked to the IAR support. This is the conclusion:
- Pre-build events are a valid solution
- Batch-build allows you to define an ordered list of projects which all need to be built together and in that specific order
- For command line compilation - no support for batch-build (which is defined on the workspace level) - so simply compile separately all the projects in the order they need to be compiled.
Personally I like the batch-build option better than pre-build events because it allows both regular building (i.e. don't build what hasn't changed) and clean rebuilding (from scratch). It's a shame though there's no support for batch-building using command line becasue this makes us define twice in two different places the projects and their ordering...
I've downloaded the midiIO library and in the readme it says:
edit the file Makefile.library and set the OSTYPE and OSSUBTYPE to match your hardware/os setup.
type "make library" to compile the library. It will be created as lib/libmidiio.a in unix.
edit the file Makefile.examples and set the OSTYPE and OSSUBTYPE to match your hardware/os setup.
Also, if you are using ALSA, then uncomment out the POSTFLAG to use the alsa library (-lasound).
type "make examples" to compile the example programs in the examples directory. The example programs will be place in the bin directory.
1 + 3 are fine but 2 + 4 are over my head. I've worked in a unix environment before and have used gcc with flags but I need to get this done in Windows. I typically use Visual Studio but don't know how to achieve this with that.. I've downloaded Dev-C++ if that's any use but I don't know what to do with the makefiles?
Ignore the makefiles and set up a fresh project in Visual C++. Make your target a static library (which will be a .lib file in Win32, not a .a file as in unix as you probably know). It is unlikely that the project will build out of the box, so you might have to deal with some compilation errors relating to unix-specific symbols. I took a quick look at the source code, and it looks fairly well-written, so I don't think you should have many problems building it directly in Windows.
Alternately, you could build the source using the real make tool in cygwin, but this means that you would need to distribute the cygwin library with your final product. This may or may not be more trouble than it's worth, especially if you are already using VC++ for the rest of your project's code.
i have source code of vc++ project. Now I am using linux.
i know how compile a single file .cpp not a whole project. So how to compile a VC project using g++ ?
A slight advantage of Makefiles would be possible integration with autotools (cough - It might prove handy to get the starting point for feature macros).[2]
There is a tool as part of winemaker that is EXCEEDINGLY helpful with fixing up a source tree that was assuming case insensitive names to work on a case-sensitive filesystem. (_it was intended mainly in order to build against winelib but that is not required)
If you want to keep using windows API's for some parts of the code, you can consider compiling with winelib (and use winegcc, producing WIN32 executables; I'm not sure whether this is what you want)
[2]: SCons is a very nice tool though
First step would be to generate Makefile out of vcproj file.
There are (obviously) some tools for that:
http://www.codeproject.com/KB/cross-platform/sln2mak.aspx
There is no easy way to do it. As others have suggested you can figure out how the build process works for this project (maybe by reading the build output in VS) and recreate that using your favorite linux build tool (scons, cmake, autotools etc.). The alternative is to use a converter tool. Aside from the below mentioned sln2mak, there is also winemaker. The docs for winemaker have a lot of old info like most linux tools docs but it can convert a .sln to a makefile. I am not sure about newer vs .sln files.
I am trying to open an existing C++ open-source library in Xcode to publish it with my own modification/additions. The library is Tesseract-OCR, which does not include a .xcodeproj file.
Since Xcode can function as an IDE, is it possible to open a bunch of files as a single project in Xcode? Is there an easy way to produce an Xcode project?
There are several ways you could do it, depending on the level of IDE integration you want. There's no direct way of importing a Makefile-based project into Xcode. You can create a project that builds via the Makefile, but you wouldn't get many of the benefits of using an IDE, since the editor features such as word completion rely on Xcode being able to parse the files in the project. You will be able to use the debugger though. To do this, create a new project and add a custom target with a script build phase that just calls down to Makefile.
If however the project you're building compiles very easily, ie without requiring a lot of macros to be set up, include paths, etc, then it may be simple to just create an empty project and merely add all source files to it. I've used this method extensively for building boost libraries. If this is a configure && make type project then you will probably have to run the configure step first, and ensure any top level config.h files are included in the project.
If the project has a complex makefile then it is likely to be an involved task to create a useful Xcode project
I realise you asked explicitly for Xcode, but in case you were actually trying to solve the problem of "I have existing C++ code which builds and runs fine from the command line, and I'd like to code and debug it in an IDE, what should I do?" my firm recommendation would be to avoid Xcode and go for Eclipse.
The reason is that as far as I can tell, Xcode has no way of ingesting the command line build environment and effectively requires you to recreate the make process inside Xcode from scratch. Fine for tiny projects, but anything with more than a few source files and it quickly becomes painful. Whereas in Eclipse everything is built around Makefiles. So in my case I got to the "step through code with working code completion" in Eclipse a lot quicker vs. never in Xcode. This of course could be because I'm an Xcode noob, but my 2c.
To create an Xcode project from an existing cmake project, you can run cmake -G Xcode. It produces some folders and files apart from the project file, so it might be better to create a folder for it first. For example:
mkdir -p build/xcode
cd build/xcode
cmake -G Xcode ../..
Xcode is a useable IDE for library creation.
Of course a good first step is to see if the one source code will build on its own with configure scripts that are included.
If not, it becomes a question of how many libraries you need to link in.
There are resources online (or at least there used to be) for using Xcode (or perhaps it's forerunner Product builder) for porting Unix projects to Mac.
Good tutorial at: http://www.macresearch.org/tutorial-introducing-xcode-30-organizer
Another good reference is Darwin Ports.
As for doing this on your own. You can build c++ based libraries in XCode. People do that every day. You can even use one of the Xcode templates to get you started.
However, library dev requires more experience with Xcode then say a simple Cocoa "Hello World" app.
The remaining questions will be assuring that the source code's dependencies are already built into the Mac's SDK. (Don't hold your breath for linking to MFC)
It's a general question... So it's a general answer.
In Xcode8,there is "Xcode->file->add files to...",then choose your files.If you want to add several files at a time,press "Cmd" when you are choosing.