RSS Forums RSS
Please support our C++ advertiser: Programming Forums

Call external program in C++ (Linux)

Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,884
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 197
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Call external program in C++ (Linux)

  #6  
Jul 22nd, 2008
The linker is complaining that you didn't link in the execprocess.obj object data.

If you are using the GCC from the command-line, make sure to compile as:
g++ -Wall -o extProg extProg.cpp execprocess.cpp

If you are using VC++ or C++Turbo or some other IDE, make sure you add execprocess.cpp and execprocess.hpp to the project before compiling.

It looks cryptic, but ld is the name of the linker on *nix systems (and also with the GCC on all supported systems). A non-zero exit status means something went wrong...

The complaints about "undefined reference to X" means that the compiler knows what X is, but it cannot find X. Since X is defined in another cpp file, that file must be compiled and linked to the cpp file containing main().

For example:
g++ -Wall -c execprocess.cpp (compile to "execprocess.o")
g++ -Wall -c extProg.cpp (compile to "extProg.o")
g++ extProg.o execprocess.o (have GCC tell the linker connect the two object files into a single executable file)
Since extProg.o uses stuff in execprocess.o, the linker puts them together so that it will work.

Hope this helps.
Last edited by Duoas : Jul 22nd, 2008 at 12:51 am.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:30 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC