Linking files together in PROS

  1. 2 weeks ago

    Parker

    Jan 1 Sheffield, Ohio 6403A

    So my biggest issue I have encountered is being able to "link" the three source files together. If I constructed a motor or sensor in initialize.cpp, I could not use it in autonomous.cpp or opcontrol.cpp. I did find rather sketchy work arounds for these, but when it came to wanting to use the gyroscope, which needs to be calibrated, I have to construct and initialize it in initialize.cpp, but then I don't know how to access the gyroscope's abilities in autonomous.cpp

  2. theol0403

    Jan 2 Courtenay, BC, Canada 7842F

    https://www.learncpp.com/cpp-tutorial/17-forward-declarations/
    https://www.learncpp.com/cpp-tutorial/1-8a-naming-conflicts-and-the-std-namespace/
    https://www.learncpp.com/cpp-tutorial/19-header-files/

    -image-

    initialize.cpp or motorConfig.cpp

    pros::Motor left_FrontDrive (LEFT_FRONT_PORT);
    pros::Motor left_BackDrive (LEFT_BACK_PORT);
    pros::Motor right_FrontDrive (RIGHT_FRONT_PORT, true);
    pros::Motor right_BackDrive (RIGHT_BACK_PORT, true);
    pros::Controller master (CONTROLLER_MASTER);

    main.h or motorConfig.hpp

    extern pros::Motor left_FrontDrive;
    extern  pros::Motor left_BackDrive;
    extern  pros::Motor right_FrontDrive;
    extern  pros::Motor right_BackDrive;
    extern  pros::Controller master;

    Now include that header file into all the other files
    And you have access to the motors throughout multiple files

  3. Parker

    Jan 2 Sheffield, Ohio 6403A

    So when I include the header file to all the other files, and put the proper stuff in the initialize.cpp and main.h files, I get no errors, but when I compile I get an error saying it can not link the project with okapilib,libpros.

  4. is there an error code number?

  5. Parker

    Jan 2 Sheffield, Ohio 6403A

    So I took of screenshot of the terminal, and I just made a motor called 'test'

  6. Deleted 2 weeks ago by sky_w8
  7. Deleted 2 weeks ago by edjubuh
  8. Deleted 2 weeks ago by edjubuh
  9. Deleted 2 weeks ago by edjubuh
  10. edjubuh

    Jan 3 V5 Beta Moderator West Lafayette, IN

    I deleted some comments that weren't relevant or helpful to the issue.

    @Parker we need a bit more info. Can you share where you've defined the test function, declared it, and are using it inside opcontrol? see also declaration vs definition .

  11. last week

    Parker

    Jan 4 Sheffield, Ohio 6403A

    So I declared the motor test in main.h, and then defined it in initialize.cpp. I am also getting another fun error. I talked to my advisor (who is a programmer) and we tinkered around with the code so it is not exactly the error is a bit more than what it was yesterday.

  12. jpearman

    Jan 4 Moderator, ROBOTC Tech Support, V5 Beta Moderator Los Angeles 8888
    Edited last week by jpearman

    You are including initialize.cpp inside both autonomous and opcontrol, that's what is causing errors, it should be removed from both. Only include header files in .cpp files.
    Also, don't add you own declarations to main.h, it's bad practise, create a new header file.

 

or Sign Up to reply!