Cannot open source file "pthread.h"


#1

I’m getting the compiliation error “cannot open source file “pthread.h” (dependency of “Drivetrain.h”)” when trying to compile last year’s source files. I am sure that means our gradle environment is not setup to access the Linux include directories - always a little tricky in a cross environment. What is the proper way to do that using gradle?

TIA


#2

This is likely caused by a known bug in the vscode extension. If you have any files open when starting vscode, they won’t grab the provided intelligence, but instead use the system defaults. As a workaround for now, you can close all the files in vscode, wait 1 minute, and then reopen them. They should then open with the correct settings.


#3

What do you mean - the wrong folder? I have the project open I an trying to build. It seems no WPIlib classes are being picked up but the build output is not complete - “‘DigitalInput’ does not name a type” and so on. It is hard to see the root cause.


#4

It was tested a lot, but there were some issues related to the update C++ extension that popped up late in the cycle. But, those libraries should be showing up no matter what. Do you have the right folder open in vscode? You want the one with build.gradle in the root directory, not in a subfolder. Also try running the command WPILib C++: Refresh C++ Intellisense, make sure that has no errors, as that will cause a reextraction and reload of all the libraries. After doing that, you should have a status bar icon on the bottom right that says linuxathena (debug) (It might be release in the paranthesis, thats ok too). If thats not there, you definitely have the wrong folder open.


#5

It is the right folder and the Intellisense build goes OK.


#6

I think it is finding the includes now and failing here:

class RhsRobotBase : public RobotBase
{

error: expected class-name before ‘{’ token

But I see RobotBase is still in RobotBase.h and this used to compile …


#7

The frc namespace shim was removed for 2019. So you need to prefix any WPILib class with frc::, e.g. frc::RobotBase instead of plain RobotBase.

You can alternatively add a using namespace frc; directive but that’s not recommended (similar to how using namespace std; is considered bad practice in C++).


#8

Thanks! I figured that out just before your post!

I’m compiling my 2018 code successfully now. Ours is in no way based on any of the templates so it was a good test of the new setup. We are multi-threaded with messages between the threads. I do need to add some custom static libraries and control the link sequence - what is the best approach in this environment.

Thanks for the help!


#9

To add a custom C++ library, you need to put the library (.a) and headers in a zip file, then add the following to build.gradle in the model {} section.

model {
  libraries {
    mylib(jaci.gradle.nativedeps.NativeLib) {
      headerDirs << 'cpp'            
      staticMatchers << '**/*.a'
    
      file = project.file("lib/mylibrary.zip")
      targetPlatforms << wpi.platforms.roborio
    }
  }
}

The above assumes the headers are located in the “cpp” directory of the .zip file, adjust as desired.

And then add ‘mylib’ to the useLibrary() call in the frcUserProgram section later in build.gradle, e.g. useLibrary(it, "wpilib", "mylib")

If you want to add custom linker args, that can be done by adding a binaries.all section in frcUserProgram, e.g.

binaries.all {
  linker.args("-L...", "-l...")
}

#10

NativeLib also has systemLibs on it, which will handle this for you :slight_smile:


#11

Gradle is telling me it can’t find the files I think. I have 5 static libs to add. Do I need a zip for each? Do I put the zip file(s) in /lib off the project root?

Could not determine the dependencies of task ‘:linkFrcUserProgramReleaseExecutable’.

Cannot find delegated dependency: cheezylib for binary: executable ‘frcUserProgram:release:executable’


#12

What does your library block in your build.gradle look like?


#13

I think they are linking now, just need to get them in the correct order. It looks like one needs to put on library in each zip.

        useLibrary(it, "wpilib", "cddlib", "coerce_goal", "gaussian_noise", "drivetrain_lib",  "polydrivetrain", "ssdrivetrain")

libraries {
cddlib(jaci.gradle.nativedeps.NativeLib) {
headerDirs << ‘cpp’
staticMatchers << ‘**/*.a’

        file = project.file("lib/libcddlib.zip")
        targetPlatforms << wpi.platforms.roborio
    }
    coerce_goal(jaci.gradle.nativedeps.NativeLib) {
        headerDirs << 'cpp'            
        staticMatchers << '**/*.a'

        file = project.file("lib/libcoerce_goal.zip")
        targetPlatforms << wpi.platforms.roborio
    }
    drivetrain_lib(jaci.gradle.nativedeps.NativeLib) {
        headerDirs << 'cpp'            
        staticMatchers << '**/*.a'

        file = project.file("lib/libdrivetrain_lib.zip")
        targetPlatforms << wpi.platforms.roborio
    }
    gaussian_noise(jaci.gradle.nativedeps.NativeLib) {
        headerDirs << 'cpp'            
        staticMatchers << '**/*.a'

        file = project.file("lib/libgaussian_noise.zip")
        targetPlatforms << wpi.platforms.roborio
    }
    polydrivetrain(jaci.gradle.nativedeps.NativeLib) {
        headerDirs << 'cpp'            
        staticMatchers << '**/*.a'

        file = project.file("lib/libpolydrivetrain.zip")
        targetPlatforms << wpi.platforms.roborio
    }
    ssdrivetrain(jaci.gradle.nativedeps.NativeLib) {
        headerDirs << 'cpp'            
        staticMatchers << '**/*.a'

        file = project.file("lib/libssdrivetrain.zip")
        targetPlatforms << wpi.platforms.roborio
    }

#14

It is linking now. FYI - it links the libraries in the reverse order listed in useLibrary(…)