IntelliSense:类型为“_TCHAR *”的变元与类型“const char *”的参数不兼容。 [英] IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"

查看:1549
本文介绍了IntelliSense:类型为“_TCHAR *”的变元与类型“const char *”的参数不兼容。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,问这样一个初学者的问题,但我真的很新openCV和VC ++ 2010。我在网上搜索一个答案,但我没有得到一个合适的。

Sorry for asking such a beginner question but I'm really new to openCV and VC++2010. I searched the net for an answer but I did not get an appropriate one.

构建OReilly-LearningOpenCV书的第一个项目第一个程序显示图片,我遇到了这些错误:

Building the first project "First Program-Display a Picture" of the OReilly-LearningOpenCV book, I encountered these errors:

1-error C2664: 'cvLoadImage' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'  
2-IntelliSense: argument of type "_TCHAR *" is incompatible with parameter of type "const char *"  

这里是代码:

#include "stdafx.h"
#include "opencv\highgui.h"


int _tmain(int argc, _TCHAR* argv[])
{   IplImage* img = cvLoadImage( argv[1] );
    cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
    cvShowImage( "Example1", img );
    cvWaitKey(0);
    cvReleaseImage( &img );
    cvDestroyWindow( "Example1" );
     system("pause");
     return 0;
 }  

这里是从Microsoft Visual Studio 2010获得的消息:

and here's the message that I get from Microsoft Visual Studio 2010:

1>------ Build started: Project: FirstProgram_DisplayAPicture3, Configuration: Debug x64 ------  
1>Build started 7/6/2013 11:13:00 AM.  
1>InitializeBuildStatus:  
1>  Touching "x64\Debug\FirstProgram_DisplayAPicture3.unsuccessfulbuild".  
1>ClCompile:  
1>  All outputs are up-to-date.  
1>  FirstProgram_DisplayAPicture3.cpp  
1>FirstProgram_DisplayAPicture3.cpp(9): error C2664: 'cvLoadImage' : cannot convert parameter 1 from '_TCHAR *' to 'const char *'  
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast  
1>  
1>Build FAILED.  
1>  
1>Time Elapsed 00:00:00.68  
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  

可能需要的其他信息:

我做了一个win32控制台应用程序,在向导的第二页我选择了预编译头设置。

我已经将项目的平台更改为x64,因为我使用win7x64作为操作系统。 br>
我已经将openCV库正确链接到我的项目。

我刚刚介绍了highgui.lib作为附加依赖关系

任何帮助都会感激。

我可以如何解决这两个错误?

Any help would be appreciated.
What can I do to solve the two errors?

已编辑部分:

请注意,这些错误发生在第6行,我的意思是行IplImage * img = cvLoadImage(argv [1 ]);

根据Roger Rowland的建议编辑的部分:

根据Roger Rowland所说,项目的字符集属性设置为未设置。

错误LNK1120:1未解析的外部

错误LNK2019:未解析的外部符号cvReleaseImage在函数main中引用

如何解决问题?

推荐答案

Unicode,这意味着 _TCHAR 宏评估为 wchar_t ,这是Windows上的16位UTF-16数据类型。但是你调用的库接受8位 char 数据。

Your project is configured for Unicode which means that the _TCHAR macro evaluates to wchar_t, which is a 16 bit UTF-16 data type on Windows. But the library you are calling accepts 8 bit char data.

因此,您需要使接口的两侧匹配。很多方法来做到这一点。显而易见的选项是:

So, you will need to make both sides of the interface match. Lots of ways to do that. The obvious options are:


  1. 将项目更改为目标ANSI(在VS项目配置中将字符集更改为多字节) li>
  2. 在调用库之前,将输入参数从UTF-16转换为ANSI。

我不必要地复杂使用 _TCHAR 这些天。当我们需要从单个代码库支持Win9x(无Unicode支持)和WinNT(支持Unicode)时,这是有用的。但我期望现在你的目标是基于NT的系统,所以你可以安全地承担对Unicode的支持。在这种情况下,您可以使用 wchar_t wstring 等。

It seems to me to be needlessly complex to use _TCHAR these days. That was useful when we needed to support Win9x (no Unicode support) and WinNT (supports Unicode) from a single code base. But I expect that nowadays you are targeting NT based systems and so you are safe to assume support for Unicode. In which case you can use wchar_t, wstring etc.

另一方面,也许这只是一个简单的程序为您的个人使用。在这种情况下,由于您的库需要8位字符,也许最简单的方法是定位ANSI。

On the other hand, perhaps this is just a simple program for your personal use. In which case, since your library wants 8 bit characters, maybe it's simplest for you to target ANSI.

但不管怎样,我宁愿怀疑 _TCHAR 只会让你困惑。我会放弃,如果我是你。

But either way I rather suspect that _TCHAR is just going to confuse you. I'd abandon that if I were you.

最后一点是你提到你的目标x64,因为你的系统是64位。请注意,64位系统可以很好地运行32位代码。如果你希望你的程序能够在32位系统上运行,并且你没有迫切需要在64位下运行,那么可能更容易定位x86。

One final point is that you mention that you target x64 since your system is 64 bit. Do be aware that 64 bit systems can run 32 bit code perfectly well. If you want your program to be capable of running on a 32 bit system, and you don't have a pressing need to run under 64 bit, then it may be easier to target x86.

您对问题的编辑提出了一个单独的问题,尽管我有预订,我会尝试回答。

Your edit to the question asks a separate question, which I'll attempt to answer in spite of my reservations.

未解析的外部符号错误表示链接器无法解析该特定符号。为了让链接器解析它,它需要传递定义该符号的.lib文件。您应该仔细检查您是否已将所有必需的.lib文件包含在其他依赖项中。从我可以收集,有OpenCV的多个.lib文件,你可能会缺少一个定义 cvReleaseImage

The unresolved external symbol error indicates that the linker could not resolve that particular symbol. In order for the linker to resolve it, it needs to be passed the .lib file that defines that symbol. You should double check that you have included all required .lib files in your additional dependencies. From what I can glean, there are multiple .lib files for OpenCV and you are probably missing the one which defines cvReleaseImage.

这篇关于IntelliSense:类型为“_TCHAR *”的变元与类型“const char *”的参数不兼容。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆