Update: The question title can be misleading. This was not Go's fault at all.
See the first comment or the accepted answer.
Run Code Online (Sandbox Code Playgroud)
以下代码(好吧,几乎相同)计算Linux下的页面视图,但在Windows下计算它们是双倍的.
有人可以找出原因吗?
package main
import (
"fmt"
"http"
)
func main() {
println("Running")
http.HandleFunc("/", makeHomeHandler())
http.ListenAndServe(":8080", nil)
}
// this version compiles and run OK under the Linux version of Golang
func makeHomeHandler() func(c *http.Conn, r *http.Request) {
views := 1
return func(c *http.Conn, r *http.Request) {
fmt.Fprintf(c, "Counting %s, %d so far.", r.URL.Path[1:], views)
views++
}
} …
Run Code Online (Sandbox Code Playgroud) 我使用Windows 7与MinGW/GCC 4.7.1.我试图double ans = pow(2,1000)
在C中执行.我发现ans
无论我在改变数据类型方面做了什么都无法正确打印.
但是,我读(这里,实际上,在最底部此页),如果同样的事情都在Linux计算机上运行,它会正确打印.
我知道我的MinGW文件夹中的limits.h文件中对char,int和long long施加的限制,但是double和float的限制在哪里?从一个操作系统或架构到下一个操作系统或架构是否可以这些?
编辑:
这是代码,它打印出截断的,零填充的答案:
#include <stdio.h>
#include <math.h>
int main(void)
{
double ans = pow(2,1000);
printf("%.0f", ans);
return 0;
}
Run Code Online (Sandbox Code Playgroud) std::to_string 不起作用是一个已知问题。甚至 std::itoa 也不适合我。我该怎么做才能将 int 转换为字符串?我不太关心性能,我所需要的只是工作而不会太慢。
编辑:我安装了最新的 mingw 32,std::to_string 仍然不起作用。我从这里安装它:http : //sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.8.1/32-bit/threads-win32/sjlj/
无论出于何种原因,MinGW 的 gcc 似乎无法找到此变量的“#define”块。完整的错误是
.../mapped.c:396:28: error: '_zzip_strcasecmp' undeclared (first use in this function)
Run Code Online (Sandbox Code Playgroud)
mapping.c 的内容:
/*
* NOTE: this is part of libzzipmmapped (i.e. it is not libzzip).
* ==================
*
* These routines are fully independent from the traditional zzip
* implementation. They assume a readonly mmapped sharedmem block
* representing a complete zip file. The functions show how to
* parse the structure, find files and return a decoded bytestream.
*
* These routines are a bit simple …
Run Code Online (Sandbox Code Playgroud) 这是我下面的代码,我正在处理。输出是这样的:
Enter Nums: 20 4
OP: Which option was that?
Run Code Online (Sandbox Code Playgroud)
这op = getchar();
部分被完全忽略了。为什么?
我正在使用 gcc 4.6.2 MinGW。
#include <stdio.h>
int add(int num1, int num2) {
return num1 + num2;
}
int subs(int num1, int num2) {
return num1 - num2;
}
int mul(int num1, int num2) {
return num1 * num2;
}
float div(int num1, int num2) {
return (float)num1 / num2;
}
int main(int argc, char* argv[]) {
int num1, num2;
char op;
fprintf(stdout,"Enter Nums: ");
scanf("%d …
Run Code Online (Sandbox Code Playgroud) 在 MSYS2 shell 中测试使用 mingw 编译的 C 程序时,我遇到了一个问题:我编写了一个命令行解析器,它根据 Windows 约定(以 开头/
)接受选项。如果我这样调用我的程序来生成一个输出文件:
./example.exe /o test
Run Code Online (Sandbox Code Playgroud)
最终的结果argv[1]
实际上是O:/
. 从运行的控制台窗口进行测试时,它工作正常CMD.EXE
。这个真正最小的程序演示了以下行为:
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc > 1)
{
puts(argv[1]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
./example.exe /o test
Run Code Online (Sandbox Code Playgroud)
所以我想这是 MSYS2 shell 试图提供帮助并将看起来像根目录下的单字母路径的东西替换为驱动器号语法。有没有办法禁用这种行为?总是启动CMD.EXE
进行测试有点麻烦。
所以我为ac程序制作了一个makefile。出于某种原因,我的“干净”不起作用。这是我的makefile的一点点:
CC=gcc
FLAGS=-c -Wall -I.
CLEANC=rm -rf *.o
move.o: move.c
$(CC) $(FLAGS) move.c
/*Lot more codes like this^^^*/
clean:
$(CLEANC)
Run Code Online (Sandbox Code Playgroud)
当我在命令提示符下运行“make clean”时,显示如下:
rm -rf *.o
process_begin: CreateProcess(NULL, rm -rf *.o, ...) failed.
make (e=2): The system cannot find the file specified.
makefile:116: recipe for target 'clean' failed
make: *** [clean] Error 2
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我做错了什么。我试过将 CLEANC 更改为
rm -f *.o
rm *.o
rm *o
rm -f *.o test.exe //test.exe is executable
Run Code Online (Sandbox Code Playgroud)
但无论我尝试什么,它仍然给我同样的错误。我真的可以使用帮助。提前致谢。
我正在尝试从Windows 上的源代码构建shapelib。该库使用自动工具。我已经安装了带有适当软件包的 MinGW。当我跑
C:\MinGW\msys\1.0\bin\sh autogen.sh
Run Code Online (Sandbox Code Playgroud)
它输出
autogen.sh: line 4: readlink: command not found
autogen.sh: line 4: dirname: command not found
**Error**: Directory `' does not look like the top-level package directory
Run Code Online (Sandbox Code Playgroud)
我不希望 readlink 可以与 Windows 一起使用,所以我直接跳过了
C:\MinGW\msys\1.0\bin\sh configure
Run Code Online (Sandbox Code Playgroud)
但是,这也会引发错误
configure: line 478: sed: command not found
configure: line 477: expr: command not found
configure: line 478: sed: command not found
configure: line 492: sed: command not found
: error: cannot create .lineno; rerun with a POSIX …
Run Code Online (Sandbox Code Playgroud) 我用以下命令编译wxWidgets-3.1.0:
C:\wxWidgets-3.1.0\build\msw>mingw32-make -f makefile.gcc
if not exist ..\..\lib\gcc_lib\mswud mkdir ..\..\lib\gcc_lib\mswud
gcc -c -o gcc_mswud\wxtiff_tif_win32.o -g -O0 -mthreads -DHAVE_W32API_H -DNDEBUG -I..\..\src\zlib -I..\..\src\jpeg -I..\..\src\tiff\libtiff -MTgcc_mswud\wxtiff_tif_win32.o -MFgcc_mswud\wxtiff_tif_win32.o.d -MD -MP ../../src/tiff/libtiff/tif_win32.c
In file included from ../../src/tiff/libtiff/tiffio.h:257:0,
from ../../src/tiff/libtiff/tiffiop.h:59,
from ../../src/tiff/libtiff/tif_win32.c:30:
c:\mingw\include\stdio.h:345:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__mingw__snprintf'
extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);
^
makefile.gcc:6018: recipe for target 'gcc_mswud\wxtiff_tif_win32.o' failed
mingw32-make: *** [gcc_mswud\wxtiff_tif_win32.o] Error 1
Run Code Online (Sandbox Code Playgroud)
我找了解决方案的链接,这没有帮助.
也遵循这一点,但得到不同的错误:
c:\mingw\include\stdio.h:345:12: error: expected '=', ',', ';', 'asm' or …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用也提供给我的 makefile 编译一些提供给我的代码。我在 Windows 10 上使用 MinGW 作为我的编译器。
我对 makefile 的经验很少,而且我创建和运行的 makefile 远没有我试图用来编译一些代码的那个复杂。
通常,当我使用 makefile 进行编译时,在命令提示符下,我会转到文件所在的目录,然后键入命令“make”并创建一个可执行文件,然后我就可以运行代码了。但是,这一次不起作用。我收到一条消息:
'make' 不是内部或外部命令,也不是可运行的程序或批处理文件。”
下面是make文件的内容:
CC=g++
CFLAGS=
INC=
LIB=
all: sorting
sorting: Driver.o Helper.o
$(CC) $(CFLAGS) -o $@ $^ $(LIB)
.cpp.o:
$(CC) $(CFLAGS) $(INC) -c -o $@ $^
Driver.cpp: Sorting.hpp Helper.cpp
Helper.cpp: Helper.hpp
clean:
rm -f *.o sorting
Run Code Online (Sandbox Code Playgroud)
我如何使用这个 make 文件来运行代码?