Tag: visual studio 2013

使用时间函数的链接列表打印错误

打印时间戳时程序崩溃。 我相信错误位于函数void flightRec_PrflightRecData(flightRecRead * thisFlight)中,它旨在做三件事: 声明时间结构的飞行时间,飞行时间是POSIX格式。 Localtime将POSIX时间转换为人类可读的时间。 第四个说明符使用asctime打印转换时间,该时间以Www Mmm dd hh:mm:ss yyyy格式打印。 错误是tb!= NULL并显示指定asctime的其他信息。 我做了什么来排除故障: 检查时间标题 检查指针和地址 关闭了弃用 检查格式说明符 任何帮助表示赞赏。 #include #include #include #include typedef struct flightRec_struct { // declare a struct to match the format of the binary data char FlightNum[7]; char OriginAirportCode[5]; char DestAirportCode[5]; int timestamp; } flightRec; typedef struct flightRecRead_struct { // […]

C:如何使数组的大小动态化?

我从书中读到:«C Primer Plus»告诉我C99标准,可以使用如下的语法: int b=4; char a[b]; 但是当我把这段代码放入vs2013时,它告诉我“表达式必须有一个常量值”。 这本书错了吗? 或者有一些我不知道的关于vs2013的新function?

Visual Studio 2013和libpng

我正在尝试使用VS2013在C中使用libpng编写一个简单的PNG文件。 我从Nuget安装了libpng并包含了png.h,但我无法编译。 我得到这个作为我的输出: 1>main.obj : error LNK2019: unresolved external symbol png_create_write_struct referenced in function writeImage 1>main.obj : error LNK2019: unresolved external symbol png_set_longjmp_fn referenced in function writeImage 1>main.obj : error LNK2019: unresolved external symbol png_create_info_struct referenced in function writeImage 1>main.obj : error LNK2019: unresolved external symbol png_write_info referenced in function writeImage 1>main.obj : error LNK2019: […]

为什么openssl / ssl.h只包含相对路径?

我通过执行以下操作使用MSVC ++ 2013 Express编译器构建了OpenSSL: 从这里安装ActivePerl 5.16.3。 抓取openssl-1.0.1e.tar.gz并将其解压缩到C:\OpenSSL\Win64 。 打开“VS2013 x64交叉工具命令提示符”并cd -ing到我解压缩归档的目录。 运行以下命令: perl配置VC-WIN64A MS \ do_win64a nmake -f ms \ ntdll.mak 这完成没有错误(构建适当的DLL)。 然而,发生了一些非常奇怪的事情。 如果我打开openssl/ssl.h ,文件的内容是: ../../ssl/ssl.h 由于这显然不是有效的C / C ++,我无法编译任何依赖于OpenSSL头的应用程序,因为上面的问题。 我做错了什么?

如何在visual studio中传递多个命令参数?

我正在使用LZMA SDK进行compession / decompression项目。 主程序包含一些我必须用来运行应用程序的参数 要从命令行运行它,我使用: ./LzmaUtil.exe e input.elf output.elf 我正在使用VS 2013,所以我已将e in.elf out.elf添加到命令参数中,我重建了项目(生成中的可执行文件)但是当我按下RUN时似乎没有任何事情发生。 请注意,我在调试文件夹中的input.elf是.exe存在于那里,而标志e用于压缩文件和output.elf是压缩文件。 主要function包括: int MY_CDECL main(int numArgs, const char *args[]) { char rs[800] = { 0 }; int res = main2(numArgs, args, rs); fputs(rs, stdout); return res; } 完整的源代码可从以下url获得: http : //www.7-zip.org/sdk.html 调试: 没有任何参数,我得到: The program ‘[5284] LzmaUtil.exe’ has exited with code […]

Visual Studio – 添加netCDF库

我想在Windows 64bit上使用Visual Studio Express 2013在C项目中使用netCDF格式。 我从官方网站下载了安装文件并执行了.exe。 然后,我查看了这篇文章 ,看看我应该如何进行链接等。更具体地说,在我的Visual Studio项目中,我做了以下内容: 把#include 在VC ++目录,库目录中,我添加了C:\ Program Files(x86)\ netCDF 4.3.3.1 \ lib; C:\ Program Files(x86)\ netCDF 4.3.3.1 \ bin; 在VC ++目录中,包含目录,我添加了C:\ Program Files(x86)\ netCDF 4.3.3.1 \ include; C:\ Program Files(x86)\ netCDF 4.3.3.1 \ bin; 在链接器>输入>附加依赖项中,我添加了netcdf.lib(以及我在netCDF 4.3.3.1的\ lib文件夹中找到的所有其他.lib文件) 在Windows \ System32和Windows \ SysWOW64中放置netCDF 4.3.3.1的\ bin文件夹的所有.dll文件 但是,当我运行项目(F5)时,它会给出以下2个错误: 错误LNK2019:函数_main中引用了未解析的外部symbol_nc_strerror 错误LNK1120:1未解析的外部 – >我认为,由于第一个错误。 […]

为什么VS2013抱怨“使用未初始化的内存”?

我有一个代码如下: #include #include typedef struct { char *a; char *b; int c; } my_type; void free_my_type(my_type *p) { if (p) { if (p->a) free(p->a); // line 12 if (p->b) free(p->b); // line 13 free(p); } } int main(void) { my_type *p = malloc(sizeof(*p)); p->a = malloc(10); p->b = malloc(10); p->c = 10; free_my_type(p); return 0; […]

为什么Visual Studio中的连续int数据类型变量位于12个字节偏移?

要澄清这个问题,请观察c / c ++代码片段: int a = 10, b = 20, c = 30, d = 40; //consecutive 4 int data values. int* p = &d; //address of variable d. 现在,在visual studio(2013年测试)中,如果p == hex_value的值(可以在调试器内存窗口中查看),那么,您可以观察到,其他变量a,b,c和d的地址是每个都有12个字节的差异! 那么,如果p == hex_value ,那么它如下: &c == hex_value + 0xC (注意hexC是十进制的12) &b == &c + 0xC &a == &b + 0xC 那么,为什么有12个字节的偏移而不是4个字节 […]

为什么DllImport for C bool as UnmanagedType.I1抛出但是作为字节工作

这是一个简单的C代码(VS 2013 C ++项目,“编译为C”): typedef struct { bool bool_value; } BoolContainer; BoolContainer create_bool_container (bool bool_value) { return (BoolContainer) { bool_value }; } 这是我的P / Invoke包装器 public partial class NativeMethods { [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern BoolContainer create_bool_container([MarshalAs(UnmanagedType.I1)] bool bool_value); } 以下是BoolContainer的托管版本: 首先是抛出MarshalDirectiveException: Method’s type signature is not PInvoke compatible. : public struct BoolContainer […]

带有指定初始化程序的MSVC12(VS2013)中可能存在的编译器错误

使用VS2013 Update 2,我偶然发现了一些奇怪的错误消息: // test.c int main(void) { struct foo { int i; float f; }; struct bar { unsigned u; struct foo foo; double d; }; struct foo some_foo = { .i = 1, .f = 2.0 }; struct bar some_bar = { .u = 3, // error C2440 : ‘initializing’ : cannot convert […]