Add shared library project's dll file to executable projects path at runtime in Eclipse - runtime

I'm using Eclipse Juno for c/c++ under Windows 7. I've created a shared library project and an executable project. I've added the shared library project as a reference in the executable project via:
executable project's properties -> C/C++ General -> Path and Symbols -> References -> check the shared library project
All this works great at compile time, I can include my shared library project's class in the executable project, and use it etc.
However when I try to run the executable project in Eclipse, I get nothing. No error, no console output. After some googling I've discovered a similar issue here:
http://www.eclipse.org/forums/index.php/m/650331/
Apparently adding the shared library project to the executable project in Eclipse, as described above, does NOT also add the dll file to the executable (.exe) file's PATH at run time inside Eclipse. As an analogy with Eclipse for Java: if you have a Java JAR project A and another Java JAR project B, by making a reference from B to A in Eclipse, B's compiled jar file IS added to A's class path when running project A inside Eclipse. I thought it would be similar with Eclipse for C/C++ but apparently it's not.
Sure enough, if I manually take the .exe file and the .dll file, place them in the same folder and run the .exe, everything works ok. Also if I copy the .dll file in to Eclipse's compilation directory for the executable project, I can run the executable project from Eclipse and it's ok.
My question is then, is there a way to have Eclipse add that shared library project's dll file to the run time when I'm telling it to run the executable project? The discussed solution in the post I link to above is to manually add the shard library project's compile directory to the Eclipse's run configuration for the executable project, namely, to add it to the PATH variable there. But I find this cumbersome and not portable, if Eclipse is managing both projects it should be able to pass all that's necessary to the run time.

Well, I've went with the manual adding of the library project's dll to the excutable project's path at run time. I did find a way to make it more portable and project location neutral (i.e. if you move both projects' source folders to another machine, and reopen them in Eclipse there, it should still work):
right click on executable project -> Run as... -> Run Configurations
in the Environment tab click "New..." to add a new environmental variable
Name your variable "PATH" and give it a value similar to this:
${env_var:PATH};${workspace_loc:/cppAStar/Debug}
where:
${env_var:PATH} is Eclipse's way of saying "get the already existing value of the PATH environmental variable as declared in Eclipse"
the ";" is to separate the exisitng PATH entries from the new one we're about to add
${workspace_loc:/cppAStar/Debug} this tells Eclipse to get the location of the workspace project named cppAStar (here cppAStar is my shared library project) and then the "/Debug" refers to where this particular project creates the .dll file when it's built.
Issues that I couldn't figure out:
the "Environment" tab in "Run configuration" has an option called "Append environment to native environment". I thought that by checking this I'd only need to add the location of the .dll dir in the PATH variable I declare here, and it will be appended to the existing PATH. However I've not managed to make this work, hence the manual re-adding of all the existing PATH before appending the new value

Unfortunately that solution does not work for the debugg configuration. See Bug 338420 -Launch configuration's Environment tab variables are not passed to the gdb process itself.
Is there a way to solve this problem for debugging? I mean except from doing post-build steps like:
cmd /c copy "${BuildArtifactFilePrefix}${BuildArtifactFileName}" "${WorkspaceDirPath}\bin\"

Related

How do I access a resource file in Xcode?

To access the resource file namefile from a program:
I ostensibly just need to check the box "target membership" to identify it as a resource file:
but this box is disabled.
What am I missing?
The helloworld target in your project is configured as a command-line tool (the square black icon that looks like a Terminal indicates this). Those compile to a single, standalone file thus Xcode cannot embed a resource file with it (which is why it's disabled).
You need to build a "Cocoa Application" target if you want to be able to include resource files. You can start a new project using the Cocoa Application template or manually add a target to your current project. You'll probably find it easier to start with a new project.
Add resource files to a command line tool
Add the file to the "Copy Files" section of your project's Build Phases:
Make sure to set Destination to "Resources", clear Subpath, and untick Copy only when installing.
Then whenever you build, Xcode will copy the file into your app's build directory, right next to the executable:
That's a screenshot of the ~/Library/Developer/Xcode/DerivedData/[your project]/Build/Products/Debug folder.
This method also works when you archive your app.
Note: if you want the file to be in some subfolder relative to the executable, e.g. res/images/, set the Subpath to that path.

Visual Studio Custom Build Default Directory Incorrect

My Visual Studio 2013 Custom Build Tool step is failing because the directory in which the step is being executed is not the directory where the project file is (which was by default the case up until recently). I can patch it by adding a cd command to the start of the step to change to the project directory but I was wondering if anyone could tell me
how this directory path is set
how to change it.
The build always assumes the project directory as 'base' directory.
This gives msbuild a set location (Builds to bin\debug is a subfolder off 'Base', reference hint paths and a lot more besides).
I would just change the execute of your tool to be reference based (i.e ....\tool.exe or similar) or make use of the path environment variables ($(OutDir),$(TargetPath),$(ProjectPath),$(TargetDir) etc).
Another option that I make use of is to have a batch file called 'post.bat' that has the necessary steps to execute a custom tool. This is then placed in the project folder and added to the project as an artefact.
Without knowing exactly where your custom tool resides relative to the project (or solution) or what the 'working directory' requirements of the custom tool are I cannot suggest more.

Visual studio compile error

I as using visual studio 2010. My solution is having more than one projects in it which are have relationships to each. When I adding a reference to a other project I can use public components (classes,enums ) of that. But when I compile it it gives error saying that those classes are not referenced(Not available).
But when I change the folder structure(When I reduce the level of folder hierarchy/when project folders borings to the root folder ex: d:\ ) it works fine.
Is it because of the length of the folder hierarchi ?
Check your namespaces
When you're adding reference, add it using Project References. So what it does is it compiles the dependencies first. Check if all projects are compiling individually.
Verify target framework versions
No, it is not because of folder hierarchy.... it is because not setting hierarchy properly !!
Follow this steps:
Lets say you have project A and project B.
Project A is dependent on Project B. So we need to add dependency of Project B to Project A.
So right click on Project A -> Open Folder in File Explorer.
Then check which folder it opens into (Lets call it "source folder") and check where the project files whose dependency to be added (Lets call it "destination folder") are located from that folder location. Add the relative path from source to destination folder. (Ex: "..\..\destination folder" ).
Add this relative path in Project A Properties -> Configuration Properties -> C/C++ ->Additional Include Directories.
Good luck.
Yes, hangar18 has suggested correctly. Add reference of each project (Static Libraries) to you execuatble project ( Console Application Project / Startup project).
Also add path of each folder where the header files and corresponding C/C++ files are residing.

XCode 3.1.2, header file not found

I have been trying to build a code that has dependencies with other header files that are not in the project directory. I added the paths to these header files in both HEADER_PATH and USER_PATH. However, I still see error while building. It says that the file is not found. I verified that the file exist in the path added to the header search path in project settings.
How do I make sure that all my header files referenced in the project is included and the paths are being picked by Xcode during compilation?
I tried copying all the files to the project with no luck. This is the first time iam using Xcode, so its kind of frustrating. Iam a linux guy and comfortable with make files. Is there a Make file for xcode which i can modify to include the header file directories.
You might want to check the order of your source files in your target's build phases to ensure that your dependencies are compiled before your source files that reference them.
Select your project in the Project Navigator.
Select your target.
Click on the Build Phases tab.
Click on Compile Sources to expand the section.
Drag the dependencies to the top of the list.
Are you sure you spelled the header file name correctly ? Is the case correct ? Did you use user quotes "" rather than system quotes <> ?
Assuming you've checked all the obvious things such as the above then one other thing to try is to quit Xcode, delete the "build" folder in your project directory, and try again - sometimes the build folder gets in a pickle internally.

Include Search Paths in TeamCity build Configurations

Normally when a Developer compiles a certain mixed C++/C# solution locally on their machine at our company, they employ the use of a .vssettings configuration file. One of the things included in this config file is reference to various directory paths for Lib and Include files.
However, our buildAgent machines (using TeamCity) are set up to be sterile, and have the bare minimum installed on them required to build any given solution/project. This means the above exampled mixed C++/C# project wont have access to the IDE's configuration where things like include search paths were set. TC accounts for this by allowing you to set all sorts of variables for any given buildConfiguration (or even by buildAgent)....
But how do I get an Include search path to WORK in TC? I'm copying down from Source Control (Perforce) a copy local of what I want Included (1), and then trying to define an Environment Variable (2) -- and yet TC fails the build (3).
I'm sure I have something configured wrong, but for the life of me cant figure out what!
Any help would be most appreciated,
blong
(1) VSC Client Mapping - Perforce
//depot/OpenSource/Boost-1.33.0/boost/... //team-city-agent/OpenSource/boost/...
(2) buildConfig Environment Variable definition
env.Include = %system.teamcity.build.checkoutDir%\OpenSource
(3) TC build log snippet
[16:57:39]: [Project "xxx.sln" (Build target(s)):] e:\buildagent\work\ef1853a454da9d94\xxx\rowsbase.cpp(5, 0): error C1083: Cannot open include file: 'boost/dynamic_bitset.hpp': No such file or directory
First, you should try to compile the solution yourself with msbuild or vcbuild on the command line, because TeamCity will do something similar. If necessary, add msbuild folder to the Path system variable. Then open the command line and type:
msbuild.exe YourSolution.sln
or
msbuild.exe YourSolution.sln /p:Configuration=Release
depending whether you want to do so in debug or release mode. This should give the same C1083 errors.
Here's the fix:
Add the path of the directories you need to add an environment variable (in fact, system variable) that I suggest you call INCLUDE.
Open the file VCProjectEngine.dll.config.xml in folder .../Microsoft Visual Studio 9.0/VC/vcpackages/.
Add the INCLUDE system variable to the include line. To me it came to replacing:
Include="$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)\include;$(FrameworkSDKDir)include"
with:
Include="$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSdkDir)\include;$(FrameworkSDKDir)include;$(INCLUDE)"
Test it works: Open a new command line (need to after you change environment variables for them to be taken into account) and try to build your solution as shown above. This has worked for me to build C++ solutions with files that #include .
Now let's have it work in TeamCity too. You can run a TC build at this point to see whether it does, but it didn't for me. Go to the "Properties and environment variables" of your TC build configuration, and add an environment variable named INCLUDE with value the same path(s) as in the INCLUDE system variable above.
Now this should work. Hope it helps.
Setting the Build Agent Service to run as a non "local System" account fixed my problem.
I ran into a problem were my C++ projects would build in Visual Studio on the build agent, but they failed when built through TC. The build agent is running windows and agent is running as a service (TeamCity Build Agent Service). The problem was that the service was being run as "Local System" instead of the user that configured Visual Studio. I change service so it would log on as the "build" user and everything worked fine.

Resources