Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 659
Shivan Dragon Avatar asked Dec 26 '22 15:12

Shivan Dragon


2 Answers

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):

  1. right click on executable project -> Run as... -> Run Configurations

  2. in the Environment tab click "New..." to add a new environmental variable

  3. 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
like image 93
Shivan Dragon Avatar answered Dec 29 '22 04:12

Shivan Dragon


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\"

like image 29
JoR Avatar answered Dec 29 '22 04:12

JoR