UPDATE2 我想我找到了问题-
当我使用以下来源的cs50文件时,它不起作用: https://github.com/cs50/libcs50/tree/develop/src
但是当我从这里使用它时,编译是可能的,没有错误: https://github.com/cs50/libcs50/releases
现在我还有其他问题,导致编译后的exe文件需要花费超过2分钟的时间才能启动-但我将把它放在另一个问题中,以便其更清晰。
UPDATE1:
我将代码更改为-,并更新了最新的cs50.c和cs50.h。文件:
#include "cs50.h"
#include <stdio.h>
int main(void)
{
string name = get_string("What is your name?\n");
printf("hello, %s\n" , name);
}
然后我再次执行了命令:
gcc string.c cs50.c
现在,我收到此错误消息:
</span> MSVC</span></td>
^
cs50.c:2959:75: error: stray '#' in program
<td id="LC458" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">pragma</span> section(".CRT$XCU",read)</td>
^
cs50.c:2959:123: error: expected identifier or '(' before '.' token
<td id="LC458" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">pragma</span> section(".CRT$XCU",read)</td>
^
cs50.c:2959:137: error: expected identifier or '(' before ',' token
<td id="LC458" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">pragma</span> section(".CRT$XCU",read)</td>
^
cs50.c:2963:75: error: stray '#' in program
<td id="LC459" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">define</span> <span class="pl-en">INITIALIZER_</span>(<span class
="pl-v">FUNC,PREFIX</span>) \</td>
^
cs50.c:2963:188: error: stray '\' in program
<td id="LC459" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">define</span> <span class="pl-en">INITIALIZER_</span>(<span class
="pl-v">FUNC,PREFIX</span>) \</td>
^
cs50.c:2967:208: error: stray '\' in program
<td id="LC460" class="blob-code blob-code-inner js-file-line"> <
span class="pl-k">static</span> <span class="pl-k">void</span> <span class="pl-e
n">FUNC</span>(<span class="pl-k">void</span>); \</td>
^
cs50.c:2967:209: error: expected identifier or '(' before '<' token
<td id="LC460" class="blob-code blob-code-inner js-file-line"> <
span class="pl-k">static</span> <span class="pl-k">void</span> <span class="pl-e
n">FUNC</span>(<span class="pl-k">void</span>); \</td>
^
cs50.c:2971:172: error: expected identifier or '(' before '<' token
<td id="LC461" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__declspec</span>(allocate(<span class="pl-s"><span class="pl
-pds">"</span>.CRT$XCU<span class="pl-pds">"</span></span>)) void (*FU
NC##_)(<span class="pl-k">void</span>) = FUNC; \</td>
^
cs50.c:2971:214: error: expected identifier or '(' before '<' token
<td id="LC461" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__declspec</span>(allocate(<span class="pl-s"><span class="pl
-pds">"</span>.CRT$XCU<span class="pl-pds">"</span></span>)) void (*FU
NC##_)(<span class="pl-k">void</span>) = FUNC; \</td>
^
cs50.c:2971:242: error: stray '##' in program
<td id="LC461" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__declspec</span>(allocate(<span class="pl-s"><span class="pl
-pds">"</span>.CRT$XCU<span class="pl-pds">"</span></span>)) void (*FU
NC##_)(<span class="pl-k">void</span>) = FUNC; \</td>
^~
cs50.c:2971:287: error: stray '\' in program
<td id="LC461" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__declspec</span>(allocate(<span class="pl-s"><span class="pl
-pds">"</span>.CRT$XCU<span class="pl-pds">"</span></span>)) void (*FU
NC##_)(<span class="pl-k">void</span>) = FUNC; \</td>
^
cs50.c:2971:288: error: expected identifier or '(' before '<' token
<td id="LC461" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__declspec</span>(allocate(<span class="pl-s"><span class="pl
-pds">"</span>.CRT$XCU<span class="pl-pds">"</span></span>)) void (*FU
NC##_)(<span class="pl-k">void</span>) = FUNC; \</td>
^
cs50.c:2975:176: error: expected identifier or '(' before '<' token
<td id="LC462" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__pragma</span>(comment(linker,<span class="pl-s"><span class
="pl-pds">"</span>/include:<span class="pl-pds">"</span></span> PREFIX
#FUNC <span class="pl-s"><span class="pl-pds">"</span>_<span class="pl-pds
">"</span></span>)) \</td>
^
cs50.c:2975:219: error: expected identifier or '(' before '<' token
<td id="LC462" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__pragma</span>(comment(linker,<span class="pl-s"><span class
="pl-pds">"</span>/include:<span class="pl-pds">"</span></span> PREFIX
#FUNC <span class="pl-s"><span class="pl-pds">"</span>_<span class="pl-pds
">"</span></span>)) \</td>
^
cs50.c:2975:241: error: stray '#' in program
<td id="LC462" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__pragma</span>(comment(linker,<span class="pl-s"><span class
="pl-pds">"</span>/include:<span class="pl-pds">"</span></span> PREFIX
#FUNC <span class="pl-s"><span class="pl-pds">"</span>_<span class="pl-pds
">"</span></span>)) \</td>
^
cs50.c:2975:293: error: expected identifier or '(' before '<' token
<td id="LC462" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__pragma</span>(comment(linker,<span class="pl-s"><span class
="pl-pds">"</span>/include:<span class="pl-pds">"</span></span> PREFIX
#FUNC <span class="pl-s"><span class="pl-pds">"</span>_<span class="pl-pds
">"</span></span>)) \</td>
^
cs50.c:2975:328: error: expected identifier or '(' before '<' token
<td id="LC462" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__pragma</span>(comment(linker,<span class="pl-s"><span class
="pl-pds">"</span>/include:<span class="pl-pds">"</span></span> PREFIX
#FUNC <span class="pl-s"><span class="pl-pds">"</span>_<span class="pl-pds
">"</span></span>)) \</td>
^
cs50.c:2975:345: error: stray '\' in program
<td id="LC462" class="blob-code blob-code-inner js-file-line"> <
span class="pl-en">__pragma</span>(comment(linker,<span class="pl-s"><span class
="pl-pds">"</span>/include:<span class="pl-pds">"</span></span> PREFIX
#FUNC <span class="pl-s"><span class="pl-pds">"</span>_<span class="pl-pds
">"</span></span>)) \</td>
^
cs50.c:2983:75: error: stray '#' in program
<td id="LC464" class="blob-code blob-code-inner js-file-line"> #ifde
f _WIN64</td>
^
cs50.c:2987:79: error: stray '#' in program
<td id="LC465" class="blob-code blob-code-inner js-file-line"> #
<span class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span cl
ass="pl-v">FUNC</span>) INITIALIZER_(FUNC,<span class="pl-s"><span class="pl-pds
">"</span><span class="pl-pds">"</span></span>)</td>
^
cs50.c:2987:248: error: expected identifier or '(' before '<' token
<td id="LC465" class="blob-code blob-code-inner js-file-line"> #
<span class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span cl
ass="pl-v">FUNC</span>) INITIALIZER_(FUNC,<span class="pl-s"><span class="pl-pds
">"</span><span class="pl-pds">"</span></span>)</td>
^
cs50.c:2987:282: error: expected identifier or '(' before '<' token
<td id="LC465" class="blob-code blob-code-inner js-file-line"> #
<span class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span cl
ass="pl-v">FUNC</span>) INITIALIZER_(FUNC,<span class="pl-s"><span class="pl-pds
">"</span><span class="pl-pds">"</span></span>)</td>
^
cs50.c:2991:75: error: stray '#' in program
<td id="LC466" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">else</span></td>
^
cs50.c:2995:79: error: stray '#' in program
<td id="LC467" class="blob-code blob-code-inner js-file-line"> #
<span class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span cl
ass="pl-v">FUNC</span>) INITIALIZER_(FUNC,<span class="pl-s"><span class="pl-pds
">"</span>_<span class="pl-pds">"</span></span>)</td>
^
cs50.c:2995:248: error: expected identifier or '(' before '<' token
<td id="LC467" class="blob-code blob-code-inner js-file-line"> #
<span class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span cl
ass="pl-v">FUNC</span>) INITIALIZER_(FUNC,<span class="pl-s"><span class="pl-pds
">"</span>_<span class="pl-pds">"</span></span>)</td>
^
cs50.c:2995:283: error: expected identifier or '(' before '<' token
<td id="LC467" class="blob-code blob-code-inner js-file-line"> #
<span class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span cl
ass="pl-v">FUNC</span>) INITIALIZER_(FUNC,<span class="pl-s"><span class="pl-pds
">"</span>_<span class="pl-pds">"</span></span>)</td>
^
cs50.c:2999:75: error: stray '#' in program
<td id="LC468" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">endif</span></td>
^
cs50.c:3003:71: error: stray '#' in program
<td id="LC469" class="blob-code blob-code-inner js-file-line">#<span cl
ass="pl-k">elif</span> defined (__GNUC__) <span class="pl-c"><span class="pl-c">
//</span> GCC, Clang, MinGW</span></td>
^
cs50.c:3007:75: error: stray '#' in program
<td id="LC470" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span class=
"pl-v">FUNC</span>) \</td>
^
cs50.c:3007:180: error: stray '\' in program
<td id="LC470" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">define</span> <span class="pl-en">INITIALIZER</span>(<span class=
"pl-v">FUNC</span>) \</td>
^
cs50.c:3011:237: error: stray '\' in program
<td id="LC471" class="blob-code blob-code-inner js-file-line"> <
span class="pl-k">static</span> <span class="pl-k">void</span> <span class="pl-e
n">FUNC</span>(<span class="pl-k">void</span>) __attribute__((constructor)); \</
td>
^
cs50.c:3011:238: error: expected identifier or '(' before '<' token
<td id="LC471" class="blob-code blob-code-inner js-file-line"> <
span class="pl-k">static</span> <span class="pl-k">void</span> <span class="pl-e
n">FUNC</span>(<span class="pl-k">void</span>) __attribute__((constructor)); \</
td>
^
cs50.c:3019:71: error: stray '#' in program
<td id="LC473" class="blob-code blob-code-inner js-file-line">#<span cl
ass="pl-k">else</span></td>
^
cs50.c:3023:75: error: stray '#' in program
<td id="LC474" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">error</span> The CS50 library requires some compiler-specific fea
tures, \</td>
^
cs50.c:3023:167: error: stray '\' in program
<td id="LC474" class="blob-code blob-code-inner js-file-line"> #<spa
n class="pl-k">error</span> The CS50 library requires some compiler-specific fea
tures, \</td>
^
cs50.c:3027:179: error: stray '\' in program
<td id="LC475" class="blob-code blob-code-inner js-file-line">
but we <span class="pl-k">do</span> not recognize this compiler/version. Pleas
e file an issue at \</td>
^
cs50.c:3035:71: error: stray '#' in program
<td id="LC477" class="blob-code blob-code-inner js-file-line">#endif</t
d>
^
cs50.c:3076:72: error: expected identifier or '(' before '<' token
<td id="LC487" class="blob-code blob-code-inner js-file-line">}</td>
^
cs50.c:3089:71: error: stray '#' in program
<td id="LC490" class="blob-code blob-code-inner js-file-line">#<span cl
ass="pl-k">pragma</span> GCC diagnostic pop</td>
^
cs50.c:3124:12: warning: missing terminating ' character
<!-- '"` --><!-- </textarea></xmp> --></option></form><form class="js-jum
p-to-line-form Box-body d-flex" action="" accept-charset="UTF-8" method="get"><i
nput name="utf8" type="hidden" value="✓" />
^
cs50.c:3124:12: error: missing terminating ' character
<!-- '"` --><!-- </textarea></xmp> --></option></form><form class="js-jum
p-to-line-form Box-body d-flex" action="" accept-charset="UTF-8" method="get"><i
nput name="utf8" type="hidden" value="✓" />
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cs50.c:3145:39: error: expected identifier or '(' before numeric constant
<li class="mr-3 mr-lg-0">© 2019 GitHub, Inc.</li>
^~~~
cs50.c:3178:12: error: stray '\342' in program
You canÔ perform that action at this time.
^
cs50.c:3178:13: error: stray '\200' in program
You canÔm perform that action at this time.
^
cs50.c:3178:14: error: stray '\231' in program
You canÔ01;31mmt perform that action at this time.
^
初始问题:
现在遇到了前面的问题中所述的相同问题-但所描述的解决方案在我看来仍然不起作用- How to link the cs50 C library in gcc on windows
这是我的代码:
#include <cs50.h>
#include <stdio.h>
int main(void)
{
string name = <get_string("What is your name?\n");
printf("hello, %s\n" , name);
}
所以尝试像这样编译程序:
gcc string.c cs50.c
这是我得到的错误:
string.c:1:10: fatal error: cs50.h: No such file or directory
#include <cs50.h>
在include语句中也使用“”而不是<>对此进行了尝试:
#include "cs50.h"
#include "stdio.h"
int main(void)
{
string name = get_string("What is your name?\n");
printf("hello, %s\n" , name);
}
然后我收到此错误消息:
string.c: In function 'main':
string.c:6:19: warning: implicit declaration of function 'get_string'; did you m
ean 'GetString'? [-Wimplicit-function-declaration]
string name = get_string("What is your name?\n");
^~~~~~~~~~
GetString
string.c:6:19: warning: initialization of 'string' {aka 'char *'} from 'int' mak
es pointer from integer without a cast [-Wint-conversion]
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\P
olzi\AppData\Local\Temp\ccwLxByO.o:string.c:(.text+0x16): undefined reference to
`get_string'
collect2.exe: error: ld returned 1 exit status
任何帮助将不胜感激-预先感谢!