标签: mingw

链接失败 - 对图形功能的未定义引用

我有使用 Visual Studio 2008 编译的 C++/Windows 程序。该程序仅包含两个 .cpp 文件。我现在尝试使用 MinGW 编译和链接它。到目前为止,我已经成功编译了两个源文件,没有错误,但是现在当我用命令链接它们时......

g++ -o program.exe file1.o file2.o
Run Code Online (Sandbox Code Playgroud)

...我得到了许多“未定义的引用..”各种图形相关函数的实例,例如:

GetStockObject, SelectObject, MoveTo, LineTo, SetPixel, TextOut, BitBlt, CreatePen etc.
Run Code Online (Sandbox Code Playgroud)

我没有得到任何其他类型的 Windows 调用的未定义引用。显然我在链接器命令行中遗漏了一些东西,但无法弄清楚是什么。

c++ windows mingw

0
推荐指数
1
解决办法
1676
查看次数

警告:函数“strcmp”的隐式声明

创建一个简单的代码来扫描两个数字,询问用户是否想要将它们相加或相乘,然后执行操作并打印输出。

#include <stdio.h>
int main(){
int num1;
int num2;
char oper[] = "";
printf("Enter a number: ");
scanf("%d", &num1);
printf("Enter another number: ");
scanf("%d", &num2);
printf("Would you like to add or multiply these numbers? ");
scanf("%s", &oper);
if(strcmp(oper, "multiply") == 0){
    int prod = num1 * num2;
    printf("The product is %d", prod);
}
else if(strcmp(oper, "add") == 0){
    int sum = num1 + num2;
    printf("The sum is %d", sum);
}
else{
    printf("Why would you input something that you knew wouldn't …
Run Code Online (Sandbox Code Playgroud)

c mingw

0
推荐指数
1
解决办法
3342
查看次数

在 C++ 中的枚举中使用访问值的正确方法是什么

我在编码时遇到过这个问题,我不确定为什么会这样。考虑这个代码

情况1

#include<iostream>

enum test{
a,b,c,d,e,f
};

int main(){
    std::cout << a;
    return 0x1;
}
Run Code Online (Sandbox Code Playgroud)

案例二

#include<iostream>

enum test{
a,b,c,d,e,f
};

int main(){
    std::cout << test::a;
    return 0x1;
}
Run Code Online (Sandbox Code Playgroud)

为什么代码都能正确编译和执行?使用test::没有必要同时使用枚举?

c++ enums mingw

0
推荐指数
1
解决办法
40
查看次数

仅当打开优化时,在函数中声明 ifstream 时出现段错误,但不在 main 中声明

正如标题所示,我遇到了 ifstream 问题。我试图读取一个文本文件,在调试时可以正常工作,但在发布版本中则不行。我能够将范围缩小到下面的示例。

如果打开优化,以下代码在到达filein的声明时会出现段错误foo()

#include <iostream>
#include <fstream>

void foo (){
    std::cout << "I'm here 3" << std::endl;

    std::ifstream file;

    std::cout << "I'm here 4" << std::endl;
}

int main()
{
    std::cout << "I'm here 1" << std::endl;

    std::ifstream file;

    std::cout << "I'm here 2" << std::endl;

    foo();

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

I'm here 1
I'm here 2
I'm here 3
Run Code Online (Sandbox Code Playgroud)

我正在使用以下命令进行编译和链接:

g++ -Wall -std=c++17 -O1 main.cpp -o main.exe 
Run Code Online (Sandbox Code Playgroud)

如果我将其更改-O1为,O0它不会出现段错误并运行到最后。我不太确定问题是什么。

我的系统是 Windows …

c++ gcc mingw ifstream segmentation-fault

0
推荐指数
1
解决办法
137
查看次数

在windows paltform的eclipse中缺少std :: vector

我正在使用eclipse 3.7.2并使用MinGW gcc 4.6.1作为我的编译器.每件事情都可以正常工作,并且我还在头文件中包含了我的源文件,但我无法在源文件中定义任何矢量类型.当我在下面的图像中注释出错误行时,每件事情都没问题并编译得很好.我无法弄清楚问题所在.

c++ eclipse mingw std

-1
推荐指数
1
解决办法
364
查看次数

g ++不会编译我的复杂模板实例化

我使用MinGW最新版本来编译以下代码.我得到了以下信息

     y:/bbom/source/om0/basic/test.cpp: In static member function 'static void somecl
ass::init(class_object*)':
y:/bbom/source/om0/basic/test.cpp:68:50: error: no matching function for call to
 'class_object::add_method(void (&)(object*, arch&))'
y:/bbom/source/om0/basic/test.cpp:68:50: note: candidate is:
y:/bbom/source/om0/basic/test.cpp:27:54: note: template<class p_function> void c
lass_object::add_method(typename p_function::funcion_type)
make.exe: *** [y:/bbom/bin/om0/basic/test.a] Error 1
Run Code Online (Sandbox Code Playgroud)

这是我的代码从这个问题不需要的每件事中脱掉

#include <exception>

class exception : public std::exception
{
    public:
    exception() {}
    exception(const exception &);
    ~exception() throw() {}
    virtual const char *what() const throw();
};

typedef unsigned id, version;
class class_object;

class object
{
    public:
    virtual ~object() {}
    void *get_method(id);
    class_object *get_class_object(); …
Run Code Online (Sandbox Code Playgroud)

c++ templates gnu mingw

-1
推荐指数
1
解决办法
131
查看次数

如何在不激怒编译器的情况下将指针传递给结构?

我正在尝试使用MinGW 4.7.2编译一个简单的C++程序,但是由于大量的错误和警告而感到沮丧.

/*\ program.h \*/
typedef struct
{   int member0;
    int member1;
    int member2;
    int member3;
} structure;

void function(&structure);
Run Code Online (Sandbox Code Playgroud)
/*\ program.cpp \*/
#include "program.h"

int main(void)
{   structure *instance;
    function(instance);
}

void function(&structure)
{   // nothing
}
Run Code Online (Sandbox Code Playgroud)

function取一个地址structure.指针instance包含structure随后传递给的地址function.

很简单,但编译器并不开心.

g++ program.cpp
In file included from program.cpp:1:0:
program.h:8:14: error: variable or field 'function' declared void
program.h:8:25: error: expected primary-expression before ')' token
program.cpp: In function 'int main()':
program.cpp:5:19: error: 'function' was …
Run Code Online (Sandbox Code Playgroud)

c++ struct mingw structure reference

-1
推荐指数
1
解决办法
175
查看次数

数据类型为char,其值范围为0-255

我在查看链接数据类型的数据类型

它被写为char类型是1字节,范围是-128到127或0到255.

这怎么可能?默认char表示签名权限. 在此输入图像描述

编辑:还有一个问题这个C代码什么问题?.但这不是同一个问题.标题说这个代码有什么问题,搜索不会轻易列出这个答案.人们必须完全分析这个问题才能理解这个问题.

编辑:看了几个答案和评论后,我又有了疑问.双引号内的字符串被视为char.如果我将双引号字符串传递给具有signed char类型参数的函数,我会收到警告.itoa和许多其他库函数也使用char类型参数而不是signed char.当然,类型转换会避免这个问题.那么操作空终止字符串的函数的最佳参数类型是什么(例如LCD显示相关函数)?使用signed char或unsigned char(因为char是实现定义的,我猜它可能不是可移植的)

c mingw

-1
推荐指数
2
解决办法
929
查看次数

CLion 的 CMAKE 错误

我是 C 编程的初学者,如果我在 CLion 上开始一个项目,我会收到此错误代码:

C:\Program Files\JetBrains\CLion 2017.2.2\bin\cmake\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\danie\CLionProjects\untitled2
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is unknown
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_COMPILER:

g++.exe …
Run Code Online (Sandbox Code Playgroud)

c mingw cmake clion

-1
推荐指数
1
解决办法
3253
查看次数

错误:无法为枕头构建轮子,这是安装基于 pyproject.toml 的项目所必需的

尝试在我的 Django 项目中使用 Pillow。尝试安装不同版本的枕头。

\n
pip install pillow\nCollecting pillow\n  Using cached Pillow-10.0.0.tar.gz (50.5 MB)\n  Installing build dependencies ... done\n  Getting requirements to build wheel ... done\n  Preparing metadata (pyproject.toml) ... done\nBuilding wheels for collected packages: pillow\n  Building wheel for pillow (pyproject.toml) ... error\n  error: subprocess-exited-with-error\n  \n  \xc3\x97 Building wheel for pillow (pyproject.toml) did not run successfully.\n  \xe2\x94\x82 exit code: 1\n  \xe2\x95\xb0\xe2\x94\x80> [198 lines of output]\n      running bdist_wheel\n      running build\n      running build_py\n      creating build\n      creating build\\lib.mingw_x86_64-cpython-310\n      creating build\\lib.mingw_x86_64-cpython-310\\PIL\n      copying src\\PIL\\BdfFontFile.py -> …
Run Code Online (Sandbox Code Playgroud)

python mingw pip python-imaging-library

-1
推荐指数
1
解决办法
2万
查看次数