Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

get_int error

Hello im taking the harvard intro to cs course and am having the following error

 

~/workspace/pset1/mario/less/ $ clang mario.c
/tmp/mario-69d749.o: In function `main':
mario.c:(.text+0x1c): undefined reference to `get_int'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

Kindof lost as ive had so many issues with cloud9...anyhow here is my code

 


#include <stdio.h>
#include <cs50.h>
int main(void)

{
int n;
do
{
int n = get_int("Height: ");

} while (n > 0 || n > 23);

for (int i = 0; i < n; i++)
{
for (int j = 0; j < n + 1; j++)
{
if (i + j >= n - 1)
printf("#");
else
printf(" ");
}
printf("\n");
}
}

 

Im honestly scared to try anymore solutions i have looked up as another non-working solution wil involve me restarting the workspace at best...or restarting my pc at worst....ive tried to use GetInt but that didnt work either. any explanation why my code isnt working would be appreciated.

4 Replies
Ground Controller Lvl 1
Message 2 of 5

Re: get_int error

add  clang -lcs50 before running ur code e.g   clang -lcs50  mario.c

Ground Controller Lvl 1
Message 3 of 5

Re: get_int error

it works. 

Is there a reason why we should add "-lcs50"?

kindly advice

Highlighted
Commander Lvl 2
Message 4 of 5

Re: get_int error

In this situation, the get_int function is an external function defined in an external library. The program cannot be built unless you tell clang the name of the external library. The "-lcs50" command line option is telling clang to use the external library "cs50". I'm assuming the external library "cs50" is provided by the professor for the class to use.

 

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Commander Lvl 3
Message 5 of 5

Re: get_int error

Hi @NickBabington , did the kind reply from @olusanyajohn90 help you out? If so, please give him some kudos and mark his answer as the accepted answer. If not, feel free to post back!


- Mark