Sysprogs forums › Forums › VisualGDB › How do I include a .h and .c in my project
- This topic has 17 replies, 2 voices, and was last updated 11 years, 5 months ago by theColonel26.
-
AuthorPosts
-
July 5, 2013 at 14:24 #600theColonel26Participant
I am trying to use the PiFace C library but I get these error when I build
[attachment=0:33qxjdp3]2013-07-05 09 20 23.png[/attachment:33qxjdp3]
#include
#include "pfio.h"
using namespace std;
class Inputs
{
public:
bool I [8];
Inputs()
{
//* constructor
}
void get()
{
for(int i = 0; i < 8; i++)
{
I = pfio_digital_read(i);
}
}
};
class Outputs
{
public:
bool O [8];
Outputs()
{
//* constructor
}
void set()
{
for(int i = 0; i < 8; i++)
{
pfio_digital_write(i, O);
}
}
};
int main(int argc, char *argv[])
{
pfio_init();
Inputs in;
Outputs out;
cout << "welcome" << endl;
bool run = true;
while (run)
{
in.get();
if(in.I[0])
{
cout << "Btn 0 Pressed" << endl;
if (out.O[0])
{
out.O[0] = false;
}else
{
out.O[0] = true;
}
}
if (out.O[4]){
run == false;
cout << "Btn 4 Pressed" << endl;
}
out.set();
}//** end while
cout << "End Run Loop" << endl;
pfio_deinit();
cout << "Press Any Key to Exit" << endl;
getwchar();
return 0;
}
July 5, 2013 at 19:23 #2503ketParticipantHi,
The undefined reference errors indicate that the linker does not know about the PiFace library. Add the library names in the flags.mak LIBRARY_NAMES variable. The library names should be separated by spaces and not include the lib prefix or the .so or .a suffixes (in this case probably just piface or piface-1.0).
As you are using the cross-compiler, the cross-toolchain probably does not include the PiFace library. You need to copy the library and its includes into the sysroot directory of the cross-toolchain from the Rasperry PI if you have not done so already.
The IntelliSense warnings look harmless in this case, it is only picking up some c code differences between Linux and Windows.
July 10, 2013 at 14:16 #2505theColonel26Participantbut shouldn’t it compile if I just added the .h and .c into my project? Intelisense has no problem finding them when I do that, but when I compile it can’t find them.
it’s just one c file and a header I think it’s just easier to add the source files to my project, but that doesn’t even work.
also where should I put the library files and includes in sysroot? in that directory or one of the it’s sub-dirs? I’ve never worked with library in C or C++ before. so I have no idea what I am doing in regards to those.
July 10, 2013 at 19:08 #2506ketParticipantHi,
Adding header and source files to the project should usually work if you are adding the files into the project directory. If you add existing files from outside the project directory, then you need to include the include directory in the mak file as otherwise make will not find the header. The source file list is updated automatically in the Makefile. IntelliSense is a Visual Studio feature and works separately from the build system.
The sysroot directory is like the root directory on Raspberry. So, everything there should be placed as it is on the Raspberry e.g. the /usr/include directory should be inside sysroot as C:SysGCCraspberryarm-linux-gnueabihfsysrootusrinclude. In the VisualGDB version 4.0 there is even a way to automatically copy these directories over: In the VisualGDB Project Properties on the Makefile settings page there is button ‘Synchronize sysroot’ next to the toolchain selection. It can copy over the selected directories automatically.
July 10, 2013 at 20:20 #2507theColonel26Participantyeah I copied them in to my project folder and then added them as existing items in VS. Intellisense seed them and removes all the red syntax error stuff, but when I try to compile I get the same error.
As for adding them in the sysroot. The library files were added to /usr/local/* there seems to be duplicate of all the gcc libraries one in /usr/* and then again in the sub dir ./local/
what is you best advice for handling that?
July 10, 2013 at 21:11 #2508theColonel26ParticipantI Installed 4.0 beta 2 but I don’t see that page in the project properties
July 10, 2013 at 23:08 #2509ketParticipantHi,
The generated makefiles were changed with version 4.0. You will not see the Makefile settings page unless you are using version 4.0 generated makefiles. On the project settings page change the build subsystem to ‘GNU Make’ and generate a new makefile. Then the Makefile settings page will appear. You can of course just make a new project as well.
July 11, 2013 at 02:20 #2504theColonel26ParticipantAlright cool I’ll try that tomorrow at work.
July 11, 2013 at 13:36 #2495theColonel26Participantok I did that, synced my sysroot, and I’m still getting the same errors.
I can compile using that library just fine on the pi if I do
gcc -L/user/local/lib/ -lpiface-1.0 -o blah2 ./blah2.c
but I can’t remote build or cross-compile with VisualGDB.
I can compile with VisualGDB if I comment out those lines that use that library though
July 11, 2013 at 19:07 #2497theColonel26ParticipantYou’re not really making a good case for why I should buy your software when I have to wait all day for a reply. This is starting to get ridiculous I have wasted days of my time on this issue. it’s just a very simple library why is this so difficult to compile.
not trying to be a jerk, I’m just getting frustrated.
July 11, 2013 at 19:44 #2498ketParticipantHi,
What have you specified in the debug.mak for the libraries? The problem occurs because the library is either not specified or not found. Based on your command line it should contain “LIBRARY_NAMES := piface-1.0”. You can also try to specify the library location in sysroot in the LIBRARY_DIRS variable. Also make sure the library actually exists in sysrootusrlocallib.
July 11, 2013 at 20:11 #2499theColonel26Participant[attachment=0:3h8cc75a]2013-07-11 15 06 43.png[/attachment:3h8cc75a]
[attachment=2:3h8cc75a]2013-07-11 15 06 05.png[/attachment:3h8cc75a]
[attachment=1:3h8cc75a]2013-07-11 15 06 19.png[/attachment:3h8cc75a]July 11, 2013 at 20:32 #2500ketParticipantHi,
That looks fine. You could try to use an absolute path for the library, but if the library would not be found the build output would state that.
Are you using ‘extern “C” { }’ around the piface include statements in your code?July 11, 2013 at 20:38 #2501theColonel26Participanthere is my code it’s a C++ project as opposed to a C project. Should still work right?
#include
#include
using namespace std;
int main(int argc, char *argv[])
{
pfio_init();
pfio_digital_write(0, 1);
pfio_deinit();
return 0;
}July 11, 2013 at 21:09 #2502theColonel26ParticipantI fail I needed a extern “C” {};
-
AuthorPosts
- You must be logged in to reply to this topic.