Question

I have a project on my local computer and I want to run/debug a cppunit Test on a server (Debian). I created the .o files with Netbeans and set the permissions to executable.

drwxr-xr-x 2 myName myGroup   4096 18. Dec 08:40 .
drwxr-xr-x 3 myName myGroup   4096 18. Dec 08:40 ..
-rwxr-xr-x 1 myName myGroup 393488 18. Dec 08:40 SisyTestData.o
-rwxr-xr-x 1 myName myGroup   3127 18. Dec 08:40 SisyTestData.o.d
-rwxr-xr-x 1 myName myGroup  30016 18. Dec 08:40 SisyTestDataRunner.o
-rwxr-xr-x 1 myName myGroup    173 18. Dec 08:40 SisyTestDataRunner.o.d

If I try to run ./SisyTestDataRunner from the directory where it is locate I get

bash: ./SisyTestDataRunner: Datei oder Verzeichnis nicht gefunden

(means: File or Directory not found)

If I try to run ./SisyTestDataRunner.o I get

bash: ./SisyTestDataRunner.o: Kann die Datei nicht ausführen.

(means: Can not execute the file)

SisyTestDataRunner looks like the following:

#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>

int main() {
    // Create the event manager and test controller
    CPPUNIT_NS::TestResult controller;

    // Add a listener that colllects test result
    CPPUNIT_NS::TestResultCollector result;
    controller.addListener(&result);

    // Add a listener that print dots as test run.
    CPPUNIT_NS::BriefTestProgressListener progress;
    controller.addListener(&progress);

    // Add the top suite to the test runner
    CPPUNIT_NS::TestRunner runner;
    runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
    runner.run(controller);

    // Print test in a compiler compatible format.
    CPPUNIT_NS::CompilerOutputter outputter(&result, CPPUNIT_NS::stdCOut());
    outputter.write();

    return result.wasSuccessful() ? 0 : 1;
}

The file SisyTestData contains one testcase that worked when I started it on my local computer (but it ran on the server).

Is it in general impossible to run a file created by netbeans from command line? Do I have to compile and link it directly on the server?

Was it helpful?

Solution 2

Ok! go in steps.

  • 1) As other reviewers have commented already correctly, the object files are generated by the compiler so that the linker can relate code libraries and generated code, in addition to carrying out more operations.

For this I think you may link directly their object files in your remote machine in this mode:

 $ g++ -o mybin myobj.o

Note that the linker should be able to find all references to the library included in the project!

  • 2) Normally in a standard C++ Project in NetbeansIDE,after you build proyect, you can find the executable file in the folder "dist" example "dist/Debug/GNU-Linux-x86" This file is ready to run on local and remote machines based on linux.

  • 3) It's possible that your executable need some system library. This library in your local machine are correctly referenced, but not in your remote machine

To resolve this problem can help you the command,

 $ ldd mybin

You can view the entire process simplified in this screenshot:

You can view the entire process simplified in this screenshot:

  • 4) I would like to clarify another important point, the NetBeans IDE can be configured to use any compiler and any settings. Currently the most common versions of NetbeansIDE under Linux are configured by default to use GCC installed on your machine and this makes clear that the object files generated from NetbeansIDE, are the same that you would generate compiled directly from console.

Steps of compilation in NetBeans:

Steps of compilation in NetBeans:

OTHER TIPS

You don't run object files. Object files are used by the linker to create the actual executable file.

Creating a program from a set of source files in C++ (or C) is done in several steps:

  1. First the current source file is passed though the preprocessor. This is the program that handles things like #include.
  2. Then the actual compiler receives the preprocessed source, and creates an object file (e.g. SisyTestData.o).
  3. All object files, and possible external libraries, are used by the linker to create the final executable program.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top