loading
 
C++ API & Compiler issue.
Anonymous
9 years
Hi,

I've started experimenting with the C++ API, however I cannot even seem to compile the example main.cpp it returns the following error.

\src\API\C++\main.cpp `main' must return `int'

The error points to this line of code in main.cpp

// This is where the program first starts
void main(int argc, char *argv[])
{
    unsigned char *image = (unsigned char *)malloc(320*240*3);

    RR_API rr;

I am using Bloodshed Dev C++ v4.9.9.2.  The C++ compiler is GCC (the GNU g++ compiler collection).  I'm running Windows XP x64 Professional Ed.

Any help getting the project kicked off would be greatly appreciated.

-Jax
Anonymous 9 years
Jax,

Some compilers may want main to return an int as the 'main' routine is a special routine (i.e. program entry point) and it normally returns an int.

Thus just replace the above with

int main(int argc, char *argv[])

and be sure to add a

return 1;

at the end of the routine. We've updated our copy too.

But it also sounds like you're somewhat new to C++? Perhaps one of the other languages would be easier to use to accomplish your task? Have you had a look at the other API options?

STeven.

STeven.
Anonymous 9 years
STeven,

Thanks for the quick response!
I've always used void main() throughout whenever my program didn't need to return the status back to the shell/OS. The compiler just gives a warning which can be safely ignored.  I guess the IDE/compiler I'm using does not agree.  I'm actually not new to C++ just very very rusty.  About 3 years ago I was the last time I used it.  That is the reason I chose it for this project (to brush up).

When I compile now I recieve a lot of warnings and then some link errors, I've provided a sample below.

\src\API\C++\RR_API.cpp In member function `int RR_API::read(int, unsigned char*, int)':
\src\API\C++\RR_API.cpp [Warning] passing NULL used for non-pointer converting 4 of `int recv(SOCKET, char*, int, int)'

...

\src\API\C++\RR_API.cpp [Warning] passing NULL used for non-pointer converting 4 of `int recv(SOCKET, char*, int, int)'
[Linker error] undefined reference to `closesocket@4'

It seems like I am just not using my IDE properly.  What Windows development environment did you create the API with?  This is the first time I've used Windows to compile anything besides a single cpp file.  I thought that since Bloodshed used the GCC compilers it would be easier to make the transation from Linux to Windows so I can use RoboRealm.

Regards,
-Jax  
Anonymous 9 years
Jax,

We use Visual Studio to compile windows programs. In your case you can download the C++ express version from the MS site for free and compile the C++ API using that. It will complain about upgrading the project (we don't use the most recent compiler for compatibility reasons) but after the conversion it should work fine.

Your errors indicate that you are missing the win32 socket library when linking. This is something that we also need to specify to link when compiling any of the source.

This is done by using

#pragma comment(lib, "ws2_32.lib")

but apparently your compiler does not support this. You will have to check the compiler settings to link to ws2_32.lib

STeven.


Anonymous 9 years
So what is the final outcome here I wasnt to sure which library to link under project options so I added ws2_32.lib from microsoft visual basic c++ but it didnt work. I am using windows xp 32 bit and dev c++ compiler. There are 4 errors this is the first.  

In function `void ReturnError(int, char*)':

warning: passing NULL used for non-pointer converting 4 of `int send(SOCKET, const char*, int, int)'

I also linked the following:


../Dev-Cpp/lib/libwin32k.a
../Dev-Cpp/lib/libws2_32.a
../Dev-Cpp/lib/libwsock32.a


Any ideas considering I am currently working with a project in dev-c++ and i need the variables from RR to be output in such a way as i can integrate them into the current project i am working with.

Thanks a billion bytes.
Blake from South Africa  [3 posts] 9 years
SO please ignore that post i posted earlier. I was confused cuz i was working with a socket extension when what i was actually looking for was the API which i now have! SO i tried to compile the API that u have 2 offer and i added the path for the RR_API.h directory. and then i added the . .. .

../Dev-Cpp/lib/libwsock32.a
../Dev-Cpp/lib/libws2_32.a

linker. .. ..it doesnt compile. Heres a copy of the compile log:

Compiler: Default compiler
Building Makefile: "C:\ROBOAPI\Makefile.win"
Executing  make...
make.exe -f "C:\ROBOAPI\Makefile.win" all
g++.exe -c API/C++/API/main.cpp -o API/C++/API/main.o -I"lib/gcc/mingw32/3.4.2/include"  -I"include/c++/3.4.2/backward"  -I"include/c++/3.4.2/mingw32"  -I"include/c++/3.4.2"  -I"include"  -I"C:/ROBOAPI/API/C++/API"    -ansi

In file included from API/C++/API/main.cpp:5:
API/C++/API/RR_API.h:89:7: warning: no newline at end of file
API/C++/API/main.cpp: In function `int main(int, char**)':
API/C++/API/main.cpp:84: error: `stricmp' undeclared (first use this function)
API/C++/API/main.cpp:84: error: (Each undeclared identifier is reported only once for each function it appears in.)

make.exe: *** [API/C++/API/main.o] Error 1

Execution terminated

Any advie would be greatly appreciated. Thanks a billion bytes once again.
Anonymous 9 years
Check your header file stricmp is only available in C header, <string.h> instead of <string>
Blake from South Africa  [3 posts] 9 years
the header file in main.cpp and RR_API.h   is <string.h>. Or am i confused about something?

I appreciate your assistance.
Anonymous 9 years
Blake,

Simply remove the

-ansi

from your makefile. It is defining

__STRICT_ANSI__

which excludes stricmp in string.h during compile. If you can't seem to remove this flag then you can also add

#undef __STRICT_ANSI__

at the very first line of main.cpp which will also do the trick.

STeven.
Blake from South Africa  [3 posts] 9 years
Steve

Thanks alot for ur help. It seemed to sort that problem out. Im getting 3 more new errors and I cant seem to find what they are referring to anywhere. Well heres the compile log.

Compiler: Default compiler
Building Makefile: "C:\ROBOAPI\Makefile.win"
Executing  make...
make.exe -f "C:\ROBOAPI\Makefile.win" all
g++.exe API/C++/API/main.o API/C++/API/RR_API.o  -o "API.exe" -L"lib" ../Dev-Cpp/lib/libwsock32.a ../Dev-Cpp/lib/libws2_32.a  

API/C++/API/RR_API.o(.text+0xe0a):RR_API.cpp: undefined reference to `CreateDIBSection@24'
API/C++/API/RR_API.o(.text+0xe77):RR_API.cpp: undefined reference to `SetBitmapBits@12'
collect2: ld returned 1 exit status

make.exe: *** [API.exe] Error 1

Execution terminated


Your time and help is much appreciated.

Kind Regards
Blake
Anonymous 9 years
Looks like you are still missing some libraries for those routines. Those are routines specific to bitmap manipulation in Windows. Most likely since you are using Mingw you don't need those so just delete the routine getBitmap from the API and things should compile fine. You can still get images from RR but they will be in RGB format (which is normally the one to use anyhow).

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index