Can't compile to run c to control ev3 motor


#1

I am attempting to compile c code to run an ev3 motor. The sensor example library example code does compile and run the motor. But when i copy and paste it to a desktop c file it wont compile i tried “sudo gcc -o program “LEGO - Motor Test.c” -lrt -lm” on the deskop but it says unreferenced so i tried “gcc -o program “LEGO - TouchSensor test.c” -lrt -lm -L/usr/local/lib -lwiringPi” and it compiles but just outputs "“BrickPiSetupSensors: -1” before it exits. Is there a book on how to wor with the c code or someway I can get this work? its a raspberry B+ brickpi module battery pack and ev3 motor. It runs with the example code but not with a copy version of it. I copied the brick.h and tick.h to the desktop too to ensure that they can be imported into main.


#2

Hey lprecovery, could this have something to do with permissions on the desktop? Could you try it in your home directory?


#3

I got it to work with sudo command line and copy the file to the brickpi_c folder on the desktop. It runs but I’m wondering where all the dependicies are. If I can only run code from within the file it’s OK but seems odd to me. I got it solved. Is it possible to only compile and run code within the folder?


#4

The only real dependencies are the ones you copied there: brickpi.h and tick.h I would double check they’re not hardcoded (like the location isn’t hardcoded) and that you’re using sudo when compiling and running. If you don’t use sudo, it won’t be able to access the GPIOs.