欢迎使用优快云-markdown编辑器

本文记录了TRDP源码在VS2010环境下成功编译后,在运行时遇到的初始化socket错误的问题排查过程。通过深入分析发现,问题是由于main函数参数传递不正确导致,特别是本地IP地址设置不符引起了socket初始化失败。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

TRDP Process data test demo main function input parameters

When i download the newset version of TRDP source code from TCNopen web. it can pass build at VS2010 compiler environment. but when run as step by step it always report out init socket function with error. deep debug in the issue. i found the issue comes from the parameters of main function, input buffer [int main(int argc, char * argv[])][6] argv[],the imput paramenter do not right. for example it transmit the local ip address as 10.0.0.220. but after check the ipconfig under cmd command windows non any ip address setting as those ip. so it may the roon reason why socket init failure.

[Organize thoughts][6]
- Check main function call by which file
- Sreach configuration file in project
- What system do before main function call
- *crtexe.c*files


Step 1 main function call

  • main function call by crtexe.c in function __declspec(noinline)int __tmainCRTStartup( void)
#ifdef WPRFLAG
            __winitenv = envp;
            mainret = wmain(argc, argv, envp);
#else  /* WPRFLAG */
            __initenv = envp;
            mainret = main(argc, argv, envp);
#endif  /* WPRFLAG */
  • Obviously system do some operation at _setargv()
  • So question is comming what does VS do before the main funciton call at file crtexe.c

Step 2 crtexe.c file analysis

This is a C file, in VC, crtexe.c provides c / c ++ main caller: wWinMainCRTStartup / WinMainCRTStartup / wmainCRTStartup / mainCRTStartup implementation. Crtexe.c file is used to generate C Run Time dynamic link library, that is, if the project uses the C Run Time dynamic link library compiler form, then compile the program entry point is used crtexe.c code

So this file just a system call seems we do not need care about what it is, but where does the parameter transmit still unknow.

  1. get a pointer to the complete command line of the new process;

  2. to obtain a pointer to the new process of the environment variable;

  3. Initialize the global variables of the C / C ++ runtime

  4. Initialize the constructor for all global and static C ++ class objects.

For a program, the mainCRTStartup or wmainCRTStartup function in the crtexe.c file is executed >before the main function is executed

step 3 where the local ip address setting from?

Search whole project and docuemtns  non files or setting define those ip address as 10.0.0.220

So, it may do not read it from file or system.

Step 4 Main function parameter passing

Redirect input or Peline there are some place send the input to main.

[“http://www.opencv.org.cn/index.php/Main%E5%87%BD%E6%95%B0%E5%8F%82%E6%95%B0argc%EF%BC%8Cargv%E8%AF%B4%E6%98%8E“][1].

Do sample test1
run [Win32TRDP_PDTest.exe][6] under cmd windows
it will alarm there is not enough parameters.

So it clean there must be some place input the paramenter to target execulte file.

Step 5 check whether VS2010 has those interface or not

indeed at VS2010

project >- property >-Configure properties -> debugging >-Command parameter

192.168.1.97 192.168.1.20 239.193.0.0 test.txt

printf("usage: %s <localip> <remoteip> <mcast> <logfile>\n", argv[0]);
printf("  <localip>  .. own IP address (ie. 10.2.24.1)\n");
printf("  <remoteip> .. remote peer IP address (ie. 10.2.24.2)\n");
printf("  <mcast>    .. multicast group address (ie. 239.2.24.1)\n");
printf("  <logfile>  .. file name for logging (ie. test.txt)\n");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值