Problem with wiringPi

Hi
I set out with the intention of connecting and communicating with
small gadgets of own design via the GPIO on Raspberry Pi, programming
in C/C++. Did not think it should be a problem. Did some googling, and
ended up looking at wiringPi as a possibility. I tried a few installs
of wiringPi on my Pi3 with Raspbian. The last installation is from
formatting link
so that should be OK, but I
can't make it work, not even the simplest example, blink.c, from the
wiringPi download.
I use Geany for editing code, compiling, building and running.
Compiling blink.c ends with "Compilation ended successfully". But
trying a Build ends with errormessages on all the functions that
should be in the library wiringPi.h. And a line with #include
WiringPi.h is in the blink.c code. Example:
extern void pinMode (int pin, int mode)
Here is a clip of some of the errormessages from Geany:
-undefined reference to 'wiringPiSetup
-undefined reference to 'pinMode
-undefined reference to 'digitalWrite
A look at the source code wiringPi.c for the library shows that the
functions are declared and defined, and they can also be found in
wiringPi.h.
So what is wrong?
Writing and running small C programs from Geany works fine, as long as
not using wiringPi. Tried going through the "Learn To Code with C"
from MagPie with Geany, and it went fine.
It has been 16 years since I took a class in C/C++ and haven't used it
since, so it is a bit rusty to say it politely. I have programmed in
other lanuages though. I have tested installs of different Linux
editions through the years but have always gone back to Windows, so I
only know the most necesssary ways to get round in Linux.
Any way, I will be gratefull for some help with this. Maybe it is best
to avoid using wiringPi for a newbe like me, but what to use then? I
would prefer to keep it in C or C++.
Best regards.
--
Jesper Kaas - jesperk@neindanke.online.no
Reply to
Jesper Kaas
Loading thread data ...
Are these messages happening at compile time or at link time?
I suspect its not that these are not defined in the header but that you aren't linking in the wiringPi library at link time...
--
The urge to save humanity is almost always a false front for the urge to  
rule. 
 Click to see the full signature
Reply to
The Natural Philosopher
Maybe I should not use Geany, but compile and link manually in a terminal window. Must find out how to do that then. Sorry for my incompetance.
But I am using Geany, which under the "Build" main menu (among others) have the options Compile, Build, Make, Make Custom Target, Make Object and Execute. No menu for linking. I am using Compile, Build and Execute. After your reply I also tried Make. I have now tried all the menu points listed above, with the following results: Compile, Make, Make Object all (with blink.c active in Geany) run successfully. Build gives the error messages described in my first message. Execute results in a terminal window with thism text: /tmp/geany_run_script_6LY5G0.sh: 7: /tmp/geany_run_script_6LY5G0.sh: ./blink: not found
Geany uses these compile commands for C++: -Compile: g++ -Wall -c "%f" -Build: g++ -Wall -o "%e" "%f"
------------------ (program exited with code: 127) Press return to continue
--
Jesper Kaas - jesperk@neindanke.online.no
Reply to
Jesper Kaas
I am getting closer now: Did a new build of wiringPi and saw the following message in the terminal: NOTE: To compile programs with wiringPi, you need to add: -lwiringPi to your compile line(s) To use the Gertboard, MaxDetect, etc. code (the devLib), you need to also add: -lwiringPiDev to your compile line(s).
So I added the text "-lwiringPi" to the compile and build commands in Geany. Now I only get the following error message when running a build: g++ -wall -o -lwiringPi "blink" "blink.c" (in directory: /home/pi/wiringpi/examples) g++: error: blink: no such file or directory Compilation failed. There is a file blink.c in directory home/pi/wiringpi/examples, so something else is nagging Geany, but what?
Best regards.
--
Jesper Kaas - jesperk@neindanke.online.no
Reply to
Jesper Kaas
Most of us set up a make file when doing more than trivial C compilations, and execute the compilation by running 'make'. Did you do that?
If not its worthwhile to create a makefile, despite the slightly archaic format (TAB is required in some lines - spaces are not an acceptable substitute) because
(a) its quite concise and describes all the steps needed to compile something together with the dependencies such as needing all modules to have been compiled before linking and which source files are needed to compile each module.
(b) make is generally faster than other approaches because make always does the the minimum amount of work needed to compile a program, e.g. if you only edited the source for one C module, then make only compiles that module before re-linking the executable.
--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie
You're trying to compile the source files called 'blink' and 'blink.c' and create an output file called '-lwiringPi'. In other words, your command line is the wrong way round. It should be:
g++ -Wall -lwiringPi -o blink blink.c
I'd suggest writing a Makefile to run the compilation and getting geany to invoke that. I wouldn't trust editors to know how to compile things right themselves (unless they're an IDE, in which case they have a million dialogues you need to fill out to get it to build)
Theo
Reply to
Theo
-Build needs a -lwiringPi
--
All political activity makes complete sense once the proposition that  
all government is basically a self-legalising protection racket, is  
 Click to see the full signature
Reply to
The Natural Philosopher
wrong order
.... -o blink -lwiringpi blink.c
--
     ?I know that most men, including those at ease with problems of the  
greatest complexity, can seldom accept even the simplest and most  
 Click to see the full signature
Reply to
The Natural Philosopher
Now I have success thanks to The Natural Philosopher, Theo and Martin Gregorie. Thank you for taking your time to answer. It really was a case of RTFM on my side, but the manual was so HUGE :-)
Best regards.
--
Jesper Kaas - jesperk@neindanke.online.no
Reply to
Jesper Kaas
We have all done it...
It's why Makefiles were invented, as, once edited, you just type 'make' and correct the latest spew of errors until it all works
Only geeks want to understand the command line syntax of gcc. The rest of is get it right ONCE and copy and edit that makefile :-)
Thx
--
There?s a mighty big difference between good, sound reasons and reasons  
that sound good. 
 Click to see the full signature
Reply to
The Natural Philosopher
There is NO currently supported wiringPi source code download, at least none by me, the author, so I've no idea where you're getting the source from. If you're using Raspbian, then sudo apt-get install wiringpi, however read this and pick another GPIO library
formatting link

And remember; wiringPi is intended for experienced C and RTB BASIC users only. It's not a newbie learning tool.
Gordon
Reply to
Gordon Henderson
Jesper,
I hope you do know/remember that the actual building also needs to be told which library to use (using "-lwiringPi" as an argument to GCC) ? The header file just describes which functions and such should be in that library.
The thing is, Geany is just a front-end for GCC, so you need to dive into it and alter the "build" commandline:
How to do it:
Geany toolbar -> "build" -> "Set build commands" -> "C commands" -> "build" -> textbox directly right of it (starting with "gcc -Wall") Append "-lwiringPi" to the end of that line.
Hope that helps.
Regards, Rudy Wieser
Reply to
R.Wieser
Hello Gordon, and thank you for the reply. First I would like to say that I did not mean to bother you with a newbie question, but hoped that some of the "regulars" on this group could help. And they sure did help. Now I can read and write to the GPIO from programcode, thanks to your wiringPi library and the kind help I recieved. The link you put in above was one of the places I visisted, so I know that you are not supporting wiringPi anymore. I googled "raspberry gpio c" to find ways of reaching the GPIO from programcode, and got several links to wiringPi stuff, so I set out to use that. If anyone can suggest a simpler C-library to use, I would be gratefull. I had a look at the code in wiringPi.c, and got blown away :-) For now wiringPiSetup, pinMode, digitalRead and digitalWrite is al I use.
Best regards
--
Jesper Kaas - jesperk@neindanke.online.no
Reply to
Jesper Kaas
Rudy:
Hi Rudy, Yes, I had not put in "-lwiringPi in Geanys build-command. I now have this: gcc -Wall -lwiringPi -o "%e" "%f" , and things started working perfect.
Best regards
--
Jesper Kaas - jesperk@neindanke.online.no
Reply to
Jesper Kaas
Jesper,
Great. :-)
Only after I posted (and looked back into the newsgroup) I noticed that your question was already several days old, and thought that you might have found the answer by now (and my suggestion would be like mustard after the meal). :-\
Regards, Rudy Wieser
Reply to
R.Wieser
I may yet want to use the GPIO and wiringPi looks like its what I would use, too.
--
Those who want slavery should have the grace to name it by its proper  
name. They must face the full meaning of that which they are advocating  
 Click to see the full signature
Reply to
The Natural Philosopher

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.