我有以下代码:
test_header.h:
typedef enum _test_enum test_enum;
enum _test_enum
{
red,
green,
blue
};
typedef struct _test_struct test_struct;
struct _test_struct
{
int s1;
int s2;
int s3;
};
Run Code Online (Sandbox Code Playgroud)
test.c的:
#include <test_header.h>
#include <stdio.h>
int main()
{
test_struct s;
s.s1=1;
s.s2=2;
s.s3=3;
printf("Hello %d %d %d\n", s.s1, s.s2, s.s3 );
}
Run Code Online (Sandbox Code Playgroud)
test_cpp.cpp:
extern "C"{
#include <test_header.h>
}
#include <stdio.h>
int main()
{
test_struct s;
s.s1=1;
s.s2=2;
s.s3=3;
printf("Hello %d %d %d\n", s.s1, s.s2, s.s3 );
}
Run Code Online (Sandbox Code Playgroud)
注意我是如何以相同的方式对结构和枚举进行类型化.当我在直接C中编译时gcc -I. test.c -o test …
我正在尝试使用一些Qwt小部件制作Qt 5应用程序,但是当我尝试链接Qwt库时,我看到Qt代码中的分段错误.我正在使用一个非常简单的Qt程序,它只弹出一个空白窗口:
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(250, 150);
window.setWindowTitle("Simple example");
window.show();
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
这在我正常编译时工作正常.一旦我添加LIBS += -lqwt到我的.pro文件,问题就开始了.它仍然可以编译,但是当我尝试运行它时,即使没有调用Qwt代码也会出现分段错误.
回溯:
Program received signal SIGSEGV, Segmentation fault.
QList (this=0x3ea60da418 <QPrinterInfoPrivate::shared_null+24>) at ../../src/corelib/tools/qlist.h:121
121 inline QList() : d(&QListData::shared_null) { d->ref.ref(); }
(gdb) bt
#0 QList (this=0x3ea60da418 <QPrinterInfoPrivate::shared_null+24>) at ../../src/corelib/tools/qlist.h:121
#1 QPrinterInfoPrivate (name=..., this=0x3ea60da400 <QPrinterInfoPrivate::shared_null>) at painting/qprinterinfo_p.h:71
#2 __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at painting/qprinterinfo.cpp:35
#3 _GLOBAL__sub_I_qprinterinfo.cpp(void) () at painting/qprinterinfo.cpp:163
#4 0x0000003e9c20f2ea in call_init …Run Code Online (Sandbox Code Playgroud)