The online racing simulator
C Programming insim
(6 posts, started )
C Programming insim
Hi there,

I'm trying to build my own 1st insim in C or C++ but i can't get it to work. I fallowed all examples here, download last helpers and libraries but still have errors. It appears that all C and C++ codes here were made to work in linux i found a nice tutorial video but it does not working in windows for somehow.

this was my steps:
1. download the Cinsim v0.6
http://www.lfsforum.net/showthread.php?t=47717

2. look all the code and see if it have any parameters to change since it have a Windows/*nix functions

3. then i couldn't compile because a missing "sched.h" include inside de Cinsim.h but i had a hard search somewhere on internet and i found it. All include file just fine now.

4. I use the source code sampleinsim.cpp found somewhere in this forums
http://www.lfsforum.net/attach ... d=111614&d=1294863787

5. and the result...

errors:
Linking...

d:\insim\c++\insim\cinsim.h(98) : error C2380: type(s) preceding 'buffer' (constructor with return type, or illegal redefinition of current class-name?)

6. i have change this part:

struct buffer
{
char buffer[PACKET_BUFFER_SIZE]; // Packet buffer - 512 should be more than enough
unsigned int bytes; // Number of bytes currently in buffer
};

to:

struct buffer
{
char buffer_pack[PACKET_BUFFER_SIZE]; // Packet buffer - 512 should be more than enough
unsigned int bytes; // Number of bytes currently in buffer
};

then results:

Linking...
sampleinsim.obj : error LNK2001: unresolved external symbol "public: __thiscall CInsim::CInsim(void)" (??0CInsim@@QAE@XZ)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: __thiscall CInsim::~CInsim(void)" (??1CInsim@@QAE@XZ)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: int __thiscall CInsim::isclose(void)" (?isclose@CInsim@@QAEHXZ)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: void * __thiscall CInsim::get_packet(void)" (?get_packet@CInsim@@QAEPAXXZ)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: char __thiscall CInsim:eek_packet(void)" (?peek_packet@CInsim@@QAEDXZ)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: int __thiscall CInsim::next_packet(void)" (?next_packet@CInsim@@QAEHXZ)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: int __thiscall CInsim::send_packet(void *)" (?send_packet@CInsim@@QAEHPAX@Z)
sampleinsim.obj : error LNK2001: unresolved external symbol "public: int __thiscall CInsim::init(char *,unsigned short,char *,char *,struct IS_VER *,unsigned char,unsigned short,unsigned short,unsigned short)" (?init@CInsim@@QAEHPADG00PAUIS_VER@@EGG
G@Z)
Debug/insim.exe : fatal error LNK1120: 8 unresolved externals
Error executing link.exe.

insim.exe - 9 error(s), 0 warning(s)


7.LNK2001 & error LNK1120 means: You're using a Win32 application project when you want a console application project. Win32 applications expect WinMain instead of main. you have to either include the implementation file for Gui class in the dll project, or link with a *.lib file that includes it in either another dll or static library.
RES: I have start my project as console not win32 App, and i do include (Cinsim.h, insim.h, pthread.h, sched.h, libpthreadGC2.a, pthreadGC2.dll) from the options in Microsoft Visual C++ 6.0 and in Bloodshed Dev-C++ but have the same errors. All files in same folders.


I just hope someone can help me in this. thank you very much.
CInSim is a C++ library and it won't work with C, but that's not the cause of your problem.

From the logs I assume you use MSVS to write and compile the application. Are you sure you have the project set up correctly? Do you have the cinsim.cpp file added to Sources in the project? Are you're linking your project against pthread library correctly? It's recommended to use phtreadVC2.lib if you want to use pthreads with MSVS. Is the CIS_WINDOWS defined in cinsim.h?
There are opensource apps written in C++ with CInSim available as MSVS project files on the forum, you can get some inspiration there as well...
Hey ty for helping Yep I'm using MSVS, if i add CInsim 0.6 source to the project i get more errors and does not make sence use both .cpp files so i had tried to use only one CInsim.cpp as it is in Cinsim.zip. i add pthread library in same folder as the project and liking them in options from MSVS and add pthread.h to the project too. phtreadVC2.lib? I think i have a diferent version... from the CInsim pack only have this files pthread.h, pthreadGC2.dll, libpthreadGC2.a. Yap, i had a look in all code and i have #defined CIS_WINDOWS and change somewhere else to windows too.

Ok i will try to find this phtreadVC2.lib and see if it works.

Ty for helping again
error:

D:\insim\C++\insim\CInsim.cpp(35) : error C2871: 'std' : does not exist or is not a namespace
D:\insim\C++\insim\CInsim.cpp(52) : error C2274: 'function-style cast' : illegal as right side of '.' operator

and multiple C2274 refering gbuf.buffer, lbuf.buffer, udp_lbuf.buffer, but this is the part of the code from Linux not windows and i have defined as #define CIS_WINDOWS in Cinsim.h. so what might be?

I will take a look another working code somewhere, if anybody have it please just post the link here or source and with all the lib need it to make it work. tyvm.
If you want to compile CInSim with MSVS, you have to rename the "buffer" struct in CInsim.h to something else, I use the name "packBuffer". Don't forget to modify the declarations of "lbuf" and "gbuf" accordingly. The errors regarding lbuf and gbuf are also caused by this.

I hate to advertise my own apps this way, but for a working 100% multiplatform example you might want to read the source of this addon. It's a bit too complex to serve as a learning example but the source is distributed as MSVS 2008 project so you can see how to set up MSVS properly to write apps with CInSim.
(The CInSim it comes with is slightly modified to take advantage of new InSim version in LFS 0.6B)
Topic solved!!
YAY congratulations is 100% working finally!! thanks to you MadCatX you have my own credits and respect. Ok, this help me kwon how does it work lets see if i can make one by myself :P Solved!

C Programming insim
(6 posts, started )
FGED GREDG RDFGDR GSFDG