标签: codeblocks

#include <string>将~43 KB添加到我的exe中

我正在使用Code :: Blocks来编写我的程序,当我包含<string>(或<iostream>)我的exe的大小增长时.我的程序非常简单,我需要保持小于20kb.我很确定这种情况正在发生,因为C++标准委员会在没有.h的情况下为许多新库交换了旧的.h版本.但是我怎么能阻止它添加~43kb?是否有Code :: Blocks的设置,以便它不会添加额外的kb或是否有我可以使用的另一个本机库?

c++ native codeblocks

2
推荐指数
2
解决办法
319
查看次数

socket()返回-1但是errno 0

我尝试在mingw上创建一个UDP套接字,但是socket()返回-1,使用errno = 0.奇怪.我已经包含了winsock2.h.最初我有编译错误undefined reference to socket@12,在设置 -lws2_32-lwsock32Code :: Block的链接器设置后,编译成功.

sockfd = socket(AF_INET, SOCK_DGRAM, 0);
RDF_LOG(kDEBUG, "sockfd %d ", sockfd);
if (sockfd < 0){
    RDF_LOG(kERROR, "ERROR: %s , errno %d\n", strerror(errno), errno);
}
Run Code Online (Sandbox Code Playgroud)

结果 - > sockfd -1错误:没有错误,错误0


好的,我改为将RDF_LOG更改为fprintf.

int tmp = 0;

sockfd = socket(AF_INET, SOCK_DGRAM, 0);
tmp = errno;
fprintf(stderr, "sockfd %d ", sockfd);
if (sockfd < 0){
    fprintf(stderr, "socket: %s , errno %d\n", strerror(tmp), tmp);
}
Run Code Online (Sandbox Code Playgroud)

返回的结果仍然是 - …

c sockets mingw codeblocks winsock2

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

错误:一个声明中有多个类型

我正在使用Code :: Blocks和Mingw32与SDL库.错误出现在我的代码的第13行(下面评论).

经过一番搜索,我认为它是一个缺失的分号(;),但这似乎并非如此.其他研究表明,它可能是包含文件中的错误.

不幸的是,包含中没有错误,即使包含被注释掉,这个错误仍然存​​在.当枚举块被注释掉时,错误会跳转到类声明的末尾.

#ifndef _TILE_H_
#define _TILE_H_

#include "Define.h"

enum
{
    TILE_TYPE_NONE = 0,
    TILE_TYPE_GROUND,
    TILE_TYPE_RAMPUP,
    TILE_TYPE_RAISED,
    TILE_TYPE_RAMPDOWN
}; //error occurs here (line 13)

class Tile
{
public:
    int TileID;
    int TypeID;

public:
    Tile();
};

#endif
Run Code Online (Sandbox Code Playgroud)

这实际上是在添加新类之后开始发生的,但是新类完全不相关,并且根本不使用,包含或继承已发布的类.

任何建议或信息都会非常感激.

编辑(添加Define.h):

#ifndef _DEFINE_H_
#define _DEFINE_H_

#define MAP_WIDTH 40
#define MAP_HEIGHT 40

#define TILE_SIZE 16

#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480

#endif
Run Code Online (Sandbox Code Playgroud)

c++ codeblocks

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

无法在codeblocks上发表评论

我正在使用代码块来学习C编程.

当我使用/* */该程序工作,但当我使用//该程序返回此错误.

expected identifier or ‘(’ before ‘/’ token|
Run Code Online (Sandbox Code Playgroud)

这是main.c

#include <stdio.h>
#include <stdlib.h>

//Ex1

int i;
float p;
char *n;

int main(void)
{
    i = 22;
    p = 70.0;
    n = "Samuel";

    printf("%s %d %.2f", n, i, p);

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

c linux codeblocks

2
推荐指数
2
解决办法
1832
查看次数

SDL2无法正常链接

我正在使用Code :: Blocks,这是我的代码:

#include "SDL2/SDL.h"
int main(int argc, char* args[]) {
    SDL_Init( SDL_INIT_EVERYTHING );
    SDL_Quit();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在建设:

mingw32-g++.exe -o C:\..\main.exe C:\..\main.o  -lmingw32 -lSDL2main -lSDL2
Run Code Online (Sandbox Code Playgroud)

得到那个:

undefined reference to "SDL_Init"
undefined reference to "SDL_Quit"
Run Code Online (Sandbox Code Playgroud)

我很确定链接器会找到libs导致如果我将它们更改为随机抱怨"找不到任何东西".

c++ linker sdl codeblocks

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

代码阻止问题

嗨,我正在做一个课程作业,我很难收到我得到的错误信息,他们是:

error 'strtoul' was not declared in this scope
error 'print' was not declared in this scope
error 'printf' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

我输入的代码是:

using namespace std;

int main (int argc, const char * argv[]) {

unsigned long int a, tmp;

a = strtoul("01011111000110001001001011010011",ULL,2);
print(a);

//We always work on "a" pattern
print(tmp = a >> 4);
print(tmp = a << 6);
print(tmp = a & (long int) 0x3);
print(tmp = a & (char) 0x3);
print(tmp = a | …
Run Code Online (Sandbox Code Playgroud)

c++ printf codeblocks

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

sdl,sdl2错误:SDL_window(等等)未声明

我已经玩C++了一段时间,最近刚开始进入SDLSDL2.

我能够让点演示程序工作.

但其他程序,如Lazy Foo'Productions的复制和粘贴似乎不起作用.我安装了SDL和SDL2(并且已卸载并重新安装.)我在Ubuntu 15.04上并且我有IDE CodeBlocks链接(-ISDL2)错误是SDL_Window- SDL_WINDOWPOS_UNDEFINED- SDL_WINDOW_SHOWN- SDL_CreateWindow- SDL_GetWindowSurface- SDL_UpdateWindowSurface最后,SDL_DestroyWindow- 未在此范围内声明.

另外,我包括:

#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
Run Code Online (Sandbox Code Playgroud)

我很确定我不需要所有这些位置,但如果没有它也无法工作.另外一点,当我输入时#includes,CodeBlocks会建议SDL2/SDL.h但不是SDL/SDL.h.

我错过了什么?

我不认为我可以在这里放入Lazy Foo代码 - 我没有得到许可......

c++ linux sdl codeblocks sdl-2

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

编译中的错误c ++代码对逗号运算符的右操作数没有影响

我的c ++代码:

std::cin >> newptr->boarding_time.hour,newptr->boarding_time.mins;
Run Code Online (Sandbox Code Playgroud)

错误:

C:\ Users\hkteco-ir\Desktop\c ++\dsdsa\main.cpp | 223 |警告:逗号运算符的右操作数无效[-Wunused-value] |

c++ compilation codeblocks cin comma-operator

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

C++程序在代码块中编译和运行,但无法在终端中编译

我创建了一个包含多个源文件和头文件的C++项目.该程序在代码块中编译和运行良好,但我无法在终端中编译它.

所有文件都在同一个文件夹中.

这是我输入的命令:

clang++ -std=c++11 main.cpp file1.cpp file1.h 
Run Code Online (Sandbox Code Playgroud)

表明:

clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
Run Code Online (Sandbox Code Playgroud)

还有一大堆错误:

error: use of undeclared identifier 'std' 
Run Code Online (Sandbox Code Playgroud)

在头文件中.

c++ terminal codeblocks c++11

2
推荐指数
2
解决办法
139
查看次数

Code :: Blocks错误:ld返回1退出状态

我正在使用Code :: Blocks v 16.1.0.0以及它附带的MINGW.链接器存在问题.我无法使用单个头/源文件链接到源文件#include "sth".为了缩小问题,我的项目中只有1个源文件和1个头文件,但无论我使用什么文件和我尝试的选项,我都无法绕过这个错误.

这是构建日志

-------------- Build: Debug in MISC (compiler: GNU GCC Compiler)---------------

gcc.exe -Wall -Wextra -Wall -g -std=c99  -c C:\Users\username\Documents\CodeBlocks\C\MISC\readFileByChars.c -o obj\Debug\readFileByChars.o
g++.exe -LC:\Users\username\Documents\CodeBlocks\C\MISC -o bin\Debug\MISC.exe obj\Debug\readFileByChars.o readFileByChars.h.gch   
readFileByChars.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Run Code Online (Sandbox Code Playgroud)

这是工具链目录:

在此输入图像描述

我之前没有任何程序运行实例.我也有MINGW独立工作(不在环境变量中包含它的bin文件夹,不要在构建期间混淆代码块),但是对于代码块,我包括安装附带的预先打包的代码块.当我单击选项链接我的项目中的头文件时,项目将无法构建(但如果我不链接文件,我如何构建我的应用程序?).我重复这个项目是空的,我只有一个标题,只包含一个源文件.我在这里看到过关于此问题的其他类似问题,但他们的解决方案无效.帮助将不胜感激.谢谢.

c linker codeblocks linker-errors ld

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