Is 'all:' is default in Eclipse makefile? - eclipse

I have c++ makefile project in Eclipse. Makefile contains lines:
executable:
$(COMPILER) $(CFLAGS) aaa.cpp -o aaa.o
$(COMPILER) aaa.o -o aaa.exe -ldl
Eclipse is not happy with executable and shows error;
make all
make: *** No rule to make target 'all'. Stop.
How to tell Eclipse to use executable instead all?

While I don't use Eclipse and couldn't tell you how to change the default build target, it may be worthwhile to have a target all since it's a pretty common thing to have.
Just specify all as the first target:
all: executable
As the first target it's also be the default target when no target is specified on the command line. Since the rule has no commands, all it does is depend on executable being built, effectively becoming an alias. To be extra safe, add
.PHONY: all
somewhere (or to existing .PHONY lines if you already have them) so that the existence of a file all won't prevent building.

Open the Makefile in the editor.
Select "Outline View" (or open it using Window -> Show View -> Outline).
In the outline view right click on "executable" and select "Add Build Target" from the drop down menu.
Go to "Build Targets" view (or open it using Window -> Show View -> Build Targets).
The target should appear in that window under the project folder name. If it is not there (quirk) select and deselect the "Hide Empty Folders" icon in the top right of that window.
Then just double click on that entry to make that target. Do the same for other targets (clean etc...).

Related

How to change default build directory path in Eclipse CDT when "Generate makefiles automatically" is enabled?

I am working on Eclipse Neon CDT where I have to enable "Generate Make Files Automatically" at C/C++ Build Settings for my project to compile. But, once I do that the build directory grays out and am unable to find a way to change the default build directory path. How do I solve this issue?
Attached is the screenshot showing the same. I need to change the build directory from workspace/Default to workspace/target.
Thanks
I'm not sure why you can't directly edit the "Build directory" when "Generate Makefiles automatically" is checked, but here is a way to indirectly get it to be what you want:
Near the top of that dialog, click "Manage Configurations..."
Create a new configuration with the name "target" (what you want your build directory to be named). You can copy settings from the Default configuration.
In the dropdown next to Manage Configurations, select the newly created "target" configuration.
Observe the Build directory change to "target" as desired.
If you follow the answer provided by HighCommander4, and use a single period as the name of the configuration, it will default to current directory. This makes sense because from the command prompt under Linux, Windows, or Apple Desktop, issuing "cd .." will traverse to the parent directory. The use of "cd ." traverses to the current directory.

How to link to cublas library in eclipse Nsight?

I am using Nvidia's example code for simpleCUBLAS. The example comes with a Makefile, or I can compile it like this:
g++ -m32 -I/usr/local/cuda/include -I. -o simpleCUBLAS.o -c simpleCUBLAS.cc
g++ -m32 -o simpleCUBLAS simpleCUBLAS.o -L/usr/local/cuda/lib -l cudart -l cublas
(the files included by the "-I." are cuda_runtime.h helper_cuda.h helper_string.h)
This compiles and runs just fine.
However, I would like to make this using Eclipse's Nsight editor for CUDA.
My Question is:
How to I add these options to Eclipse (the -L/usr/local/cuda/lib -l cudart -l cublas, & the -I.) Nsight?
Other details:
Am using Linux.
I've seen some info elsewhere for Eclipse & c/c++ Project, BUT here I am using cuda c/c++ Project.
Thanks.
I don't think any of this is specific to Nsight Eclipse Edition. What you are trying to do are standard operations for any C/C++ project built using Eclipse. Nsight EE doesn't change these steps in any major way. You can get help easily enough on these topics using the built-in Eclipse help in Nsight EE. For example:
open help (select help...help contents)
in the search box type "add library"
click on the first item returned in the help search pane
All of your questions (adding library paths, adding libraries, adding include paths) have to do with the Project Properties. We can access these properties directly by:
Open the project in Nsight EE
In the project pane on the left, right-click on the project whose properties you wish to inspect/modify, then select "Properties" from the pop-up menu (the last item in the menu)
The project properties pane is now open.
Click on the triangle next to "General" in the properties dialog. This will open the "General" sub-menu.
Under General, click on "Paths and Symbols" The generic Eclipse help would have taken you this far.
Now click on "CUDA C" (Yes this is the one step that is different.)
The tabs across the top now include selections for things like "Includes", Libraries", "Library Paths" etc. By selecting any one of these tabs, you can add or modify the appropriate entries.
So as one example, let's add the cublas library. Select the "Libraries" tab.
Now click the "Add" button
Enter the name of the library. It is cublas, not lcublas, and not -lcublas
now click "OK", "Apply" and exit out of the properties, build your project, and confirm that -lcublas has been added to the build command

Disable automatic "Updating projects..." action in Eclipse CDT

I am using a quite large project in Eclipse, composed by different libraries which can be build independently thanks to dedicated "Make Target" elements.
When compiling one of this libraries, the compilation works fine, but afterwards, Eclipse keeps busy by doing "Building Targets. Updating projects..." (as named in the Progress View). As my project is rather large, this action takes several minutes, preventing me to start new compilations or change Eclipse settings.
Is there any way to disable this automatic update in Eclipse?
I have observed this behaviour in Eclipse Helios and Eclipse Juno.
I have tried to remove my "Make target" objects, and give an invalid C/C++ Build configuration (e.g., provide an invalid make command).
As expected, when building the project, Eclipse tries to execute the invalid make command (which fails), but then keeps doing this "Updating projects..." anyway...
After build Eclipse is looking for newly created executables. If your project is Makefile-based Eclipse cannot be sure where to search and browses the whole source tree.
Assuming your executable are all go into a folder bin-XXX, you can reduce these searches as following:
Select the top project (say "src") and go to the right-menu dialog “Properties” (alternatively: top menu Project-Properties). Then go to “C++ build”-“Refresh policy”. Here select the folder “src” and press “Add Exception”. Then add all folders except “bin-XXX” as an exception.
Select the top project “src” and go to the right-menu dialog “Properties” (alternatively: top menu Project-Properties). Then go to “C++ General – Paths and Symbols – Output Location”. Add folder “bin-XXX” and remove the folder “src”

Getting XCode to include, compile and link existing (C++) codebase in XCode 4.3(.1)

I'm trying to 'import' my existing C++ codebase into my XCode iOS project.
Problem is, xCode won't compile (and therefore not link) my code.
This is what I've done so far:
File > Add files to "Project". I don't tick 'Copy files' since it's a shared codebase for multiple platforms and multiple copies of source code is not an option.
I've added appropriate path to the "Header Search Path" project settings. Including header files works, I can #include "stuff.h" from my Objective-C++ (.mm) file.
However, I can't find any way of actually telling XCode to compile the .cpp files?
A few points:
I'm not looking for a way to pre compile it into a library and linking that way
The project is a standard iOS Objective-C project. The C++ code is called from it (that's not a problem)
Update
I've added the codebase directory to the target's "Compile Sources". I actually have to click "Add other..." in the dialog that pops up, since I can't select the directory reference to my codebase.
When I add it, XCode asks me if I want to "Create external build system project". I leave it ticked and the two fields with the default values "/usr/bin/make" and "$(ACTION)". However, my codebase doesn't get compiled during the build. Do I have to write my own Makefile ?
If I don't select "Create external build system project" then a directory reference is created under the target, but not compiled during the build and a warning is emitted:
warning: no rule to process file '$(PROJECT_DIR)/../codebase'
of type folder for architecture i386
Even if you don't check Copy Files you have to check Add to Targets when adding the files to the project.
If you forgot to do that, you can select the target, go to the Build Phases tab and add the files to Compile Sources.
If you go to your Targets -> Build Phases -> Compile Sources -> "+" -> "Add Others" -> (select your external source folder) -> Select: Create Group for any added folders -> Unchecked: Copy items into destination.
Now your folder will be in XCode, mimic the structure. If you add source files to that folder in XCode the source files will be added to your external source directory just fine. So the ease of using multiple IDEs and having to manage source linkage is solved.
The catch. You still have to manually add files into the "Compile Sources" area. This is rather simple. Just click and drag your source files from the group directory in XCode right into the Compile Sources window. So there is an extra step when you add a source file now. Forgetting to add them to the Compile Sources window will yield unresolved symbols compile errors.

Possible to validate xml against xsd using Objc/iPhone code at runtime

I have xml files that I read in at runtime, is it possible to validate the xml against an xsd file at runtime using Obj C?? This can be done in java and c#.. But i need do it run time in my iphone app.
I don't think you can do this using Obj C on iOS. I think you'll need to use libxml2.
Here's an example of a simple C program that validates XML against XSD.
Here are instructions on adding libxml2 to an XCode project.
CodeSynthesis XSD/e
should support iPhone (inside the Mac package)
Edit #1: Setup instruction
To build the XSD/e runtime library (libxsde.a), perform the following steps:
Unpack the pre-compiled XSD/e package for Mac OS X.
Start a new terminal window and run the following commands:
cd xsde-3.2.0-i686-macosx
cp etc/ios/config-xcode.make config/config.make
Don't close the terminal.
Edit config/config.make and adjust the XSD/e configuration to suit your
requirements.
In the terminal, execute:
cd libxsde
make
If the make command is not found, try /Developer/usr/bin/make (or your
alternative XCode installation directory).
Start XCode and perform the following steps:
5.1 Select "File"->"New Project"
5.2 In the opened dialog select "iOS Library"->"Cocoa Touch Static
Library". Click "Choose...".
5.3 In the next dialog type libxsde in the "Save As" field and navigate
to the xsde-3.2.0-i686-macosx directory. Click "Save".
5.4 Next you should see a warning dialog saying that the libxsde directory
already exists. This is expected so click "Replace".
5.5 In the project window in the "Groups & Files" list select "Other
Sources" group, then select "Project"->"Add to Project...".
5.6 In the opened dialog navigate to the xsde-3.2.0-i686-macosx/libxsde directory and
select the src directory. Click "Add".
5.7 In the next dialog leave the default settings and click "Add". Now
you should see multiple source files (.cxx and .c) listed in the
"Other Sources" group.
5.8 Next select "Project"->"Edit Project Settings", "Build" tab. In the
"Configurations" drop-down list select "All Configurations".
5.9 Scroll down to the "Search Paths" section and add . (dot) to the
"Header Search Paths" field.
5.10 Scroll down to the "GCC 4.2 - Language" section and add the
-fvisibility=hidden flag to the "Other C Flags" field as well
as the -fvisibility=hidden and -fvisibility-inlines-hidden flags
to the "Other C++ Flags" field. If you set any extra C/C++ flags
in your application's project, you may also want to add them here.
5.11 Build the project for all the desired configurations (for example,
Debug/Release, Device/Simulator, ARMv6/ARMv7, etc).
In the terminal window create "fat" libraries by running the following
commands (which may need to be adjusted depending on the configurations
that you have built):
cd build
lipo -output libxsde.a -create Release-iphonesimulator/liblibxsde.a Release-iphoneos/liblibxsde.a
lipo -output libxsde-d.a -create Debug-iphonesimulator/liblibxsde.a Debug-iphoneos/liblibxsde.a
If at some point you need to change the XSD/e configuration then it is best
to start from scratch (step 1 above) since the set of files that is added
to the XCode project may vary from configuration to configuration.
Once the runtime library is built, to integrate XSD/e into your application
perform the following steps:
Compile your schemas to C++ with the XSD/e compiler (xsde-3.2.0-i686-macosx/bin/xsde)
and add the resulting generated C++ files to your project.
To link your application to the XSD/e runtime library (libxsde), perform
the following steps in your project:
2.1 In the "Targets" group, double-click on your application to open the
"Info" dialog.
2.2 Select the "General" tab and click on the Plus (+) button to add the
library.
2.3 In the opened dialog click the "Add Other..." button and add either
the libxsde.a or libxsde-d.a (debug) fat library created above.
To add the XSD/e runtime headers to your application's search paths,
perform the following steps in your project:
3.1 Select "Project"->"Edit Project Settings", "Build" tab. In the
"Configurations" drop-down list select "All Configurations".
3.2 Scroll down to the "Search Paths" section and add the path to the
xsde-3.2.0-i686-macosx/libxsde directory to the "Header Search Paths" field.
3.3 Build the application.
there are no sdks for this in the objC Api for iOS. To do this you have to drop down to using libxml's C APIs directly.
you load the xml (e.g. xmlReadMemory)
then for XSD you'd use xmlSchemaValidateDoc
or you can use the following wrapper class [disclaimer: I am the author]:
DDXMLValidator (part of my helpers # https://github.com/Daij-Djan/DDUtils/)
//validate
NSError *error = nil;
NSURL *schemaURL = [[NSBundle mainBundle] URLForResource:#"XMLSchema" withExtension:#"xsd"];
if(![[SNXMLValidator sharedInstace] validateXMLData:xmlData withSchema:SNXMLValidatorSchemaTypeXSD schemaFile:schemaURL error:&error]) {
DebugLog(#"Failed to validate data: %#", error);
}
the class can do DTD, XSD, RelaxNG (it just wraps libxml2)