我正在学习在C编程中使用getline,并尝试了http://crasseux.com/books/ctutorial/getline.html中的代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int atgc, char *argv[])
{
int bytes_read = 1;
int nbytes = 10;
char *my_string;
my_string = (char *)malloc(nbytes+1);
puts("Please enter a line of text");
bytes_read = getline(&my_string, &nbytes, stdin);
if (bytes_read == -1)
{
puts ("ERROR!");
}
else
{
puts ("You typed:");
puts (my_string);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,问题是编译器不断返回错误:未定义的引用'getline'.你能告诉我问题是什么吗?谢谢!
我使用的是Win7 64bit + Eclipse Indigo + MinGW
GNU make 会自动删除我的目标文件。我不明白为什么......我的目标是生成小型测试程序,因此每个源文件都是一个独立的程序,不使用其他模块。
我的生成文件是:
# This makefile is written for Windows cmd shell
SHELL=C:\Windows\System32\cmd.exe
# FILES
SRCS=$(wildcard src/*.cpp)
BINS=$(patsubst %.cpp,bin/%.exe,$(notdir $(SRCS)))
all:compile
obj/%.o:src/%.cpp
g++ -Wall -Wextra -std=gnu++11 -m64 -D_WIN32_WINNT=0x0400 -c -o $@ $<
bin/%.exe:obj/%.o
g++ -Wall -Wextra -std=gnu++11 -m64 $^ -o $@
clean:
if exist obj\*.o del /Q obj\*.o
mrproper:clean
if exist bin\*.exe del /Q bin\*.exe
compile:$(BINS)
rebuild:clean all
.PHONY:all compile clean mrproper rebuild
Run Code Online (Sandbox Code Playgroud)
例如,使用单个源文件运行 GNU make 的操作如下:
g++ -Wall -Wextra -std=gnu++11 -m64 -D_WIN32_WINNT=0x0400 -c -o obj/Tester.o src/Tester.cpp
g++ -Wall …Run Code Online (Sandbox Code Playgroud)