How to link to cublas library in eclipse Nsight? - eclipse

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

Related

Gtkmm in Eclipse makefile project: "could not be resolved"

I am trying to migrate a custom C++ project which uses Gtkmm3.0 to Eclipse (Oxygen) on Ubuntu 16.04. The project has its own Makefile and builds fine from the terminal within Eclipse. What I have not been able to do so far is tell the indexer about Gtkmm, and I get lots of these (which is very annoying):
When I hover over the little red bugs, it says:
Type 'Cairo::RefPtr<Cairo::Context>' could not be resolved.
I have done a lot of Googling on this and found nothing so far because all answers seem to assume the project's build tools are managed by Eclipse (See this or this, for example). In my case I have a makefile project instead of an executable project and hence some options are not available to me. For example, the first links speaks about configuring the builder:
We have to add all this directories. On Eclipse select the Project->Properties menu option. Select C/C++ Build->Settings property page and GNU C++ Compiler->Directories from the Tool Settings tab. Now we have to add all directories. In my case (Makefile project) only two tabs are available there: Binary Parsers and Error Parsers.
How can I tell the Eclipse indexer I am using Gtkmm3.0?
Found the solution that works for me:
Open a terminal and enter:
pkg-config --cflags gtkmm-3.0
You will see a list of includes directories (starting with -I). These are the directories you want to add in Eclipse so that it can locate the Gtkmm symbols in the editor.
In Eclipse, go to:
Project -> Properties -> C++ General -> Paths and Symbols
In the Includes tab, select GNU C++. You need to add here add the include directories found in step 1. There is no automated way to do this, yo must enter them one by one.
One trick that can save you some time is to edit manually the Eclipse project setting XML file and add the include directories directly in the XML file. By the end, you should have something that looks like this:
That did it for me, hope this helps!

Eclipse: Error "Variable references empty selection: ${resource_loc}"

I have found that using the Eclipse "external tools" launch configuration is the best way to open my favorite editor on the current file in Eclipse, notably offering a one-time and super-flexible configuration versus the "Open With" menu, which I had tried to use beforehand and always found wanting, constraining, limiting, and requiring repetitive work for many file types. I set up this external tool as follows and this works great for files in my project:
Run:External Tools:External Tools Configurations...
New launch configuration
On the "Build" tab, un-check "Build before Launch"
On the Common tab, check "External Tools" under the "Display in favorites menu"
On the Main tab, enter "/usr/bin/myeditor" for the Location
Under "Working Directory" I am able to leave this blank
Under arguments ${resource_loc}
(At the top, in the "Name" field whatever I want the name to show up as)
I originally found this general technique for launching an external editor right here on stackoverflow.
So you can see ${resource_loc} or ${resource_path} is the one and only variable I need for this to work, and it does work great when I open a file located inside my Eclipse project and click the external tool. That part is fine.
But the problem I have just discovered occurs when I open a file that is not specifically listed in my project and then click the external tool button. It no longer works and I get an error dialog saying: "Variable references empty selection: ${resource_loc}."
Specifically, to reproduce this, I can create a new C++ "Hello World" project (CDT is included in my Eclipse along with Java) then add the line #include "/tmp/whatever.h" at the top of the one cpp file in the project and then right-click on "/tmp/whatever.h" and use the command "Open Declaration" and Eclipse kindly opens the file /tmp/whatever.h. Finally, I invoke my external tool intending to view whatever.h in my editor, and bang, that's when the problem occurs. (Before doing this I put a harmless line of commented text into /tmp/whatever.h.)
Before some SOer asks, no I am not actually trying to #include "/tmp/whatever.h". I am using this #include example as a specific way to show how the error can be reproduced. If you must know, in my case I actually observed the error when trying to open the editor while using Eclipse to browse framework files, files that are not part of my project.
I have already tried ${resource_path} to see if maybe that might have something in it in this context, but same error, and I have looked at the documented list of Eclipse launch variables here and again I don't see anything that looks like it would be more well-defined in the context of a file that is not part of the current project.
My assessment right now is that this is an unsolvable problem and likely just a limitation of trying to use the "External Tools" for this editor launching business. I only settled on that after using the default "Open With" menu in Eclipse for a while and finding the whole setup there highly unsatisfactory and requiring repeated configuration and actually IIRC it just would not work at all I believe in the context of my editor and controlling how many windows are created, whether one or many or one per project etc. Above, I simplified the launch for demonstration purposes.
OS: GNU/Linux Xubuntu 15.10.
Eclipse: Mars.1 Release (4.5.1) Build id: 20150924-1200
You can circumvent the "Workspace is the top-most Eclipse place" rule by linking files (or folders for that matter) in a project.
Example:
Create a new project:
File → New → Project → General → Project → Next → Project name: LinkProject → Finish
Create a file outside-workspace anywhere outside your Eclipse workspace dir.
Import this file as link:
Select LinkProject → File → Import... → General → File System → Next > → From directory: <as chosen for the file above> → Check ☑️ 📄 outside-workspace→ (⚠️ The next can be overlooked easily!) Advanced >> → Check ☑️ Create links in workspace → Finish
NB: I doesn't matter whether you uncheck  ☐ Create link locations relative to: PROJECT_LOC     ˅  or what you select from the list. ${resource_loc} is always the same. Just the file's/folder's Properties → Location: changes. There is a new property for linked files/folders: Resolved location which shows what ${resource_loc} is resolved to: an FQFN.
And, once you linked a file/folder in your project it is part of your project and you can also access it relatively, e.g. with ${workspace_loc:/LinkProject/outside-workspace}' which resolves to the FQFN, too.
See also Eclipse Platform User Guide – Linked resources.

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”

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)

"Export" button in Eclipse CDT "Paths and Symbols" dialog?

On the Includes tab of the Paths and Symbols section of the Project Properties dialog in the Eclipse CDT, there is an "Export" button:
The best documentation I have found says that this "toggles whether the selected include path is exported or not." If I click it, it changes to "Unexport" and "[exp]" is appended to the selected include path.
What exactly does this do? What does it mean to "export an include path?"
This button makes the path in question available to projects which reference your current project. Project references can be configured using the References tab in the same "Paths and Symbols" group shown in your screenshot.
This functionality has been improved in the next version of CDT (7.x). It allows you to create dependencies between projects and have include, library and library files being propagated automatically. (In the next version you can alter the order of the referenced projects...)
See also the Export Settings page which can be enabled with
Window > Preferences > C/C++ >
Property Page Settings > Display
"Export Settings" Tab