Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compute/fix sum-array-bugs/seg-fault Makefile #28

Merged
merged 1 commit into from
Nov 19, 2023

Conversation

razvang0307
Copy link

Add -pthread to LDFLAGS when compiling using <pthread.h>.

@github-actions github-actions bot added area/code Update or new source code support / solution files topic/compute Related to "Compute" chapter kind/improve Improve / Update existing content / item labels Nov 15, 2023
@Alex-deVis Alex-deVis requested a review from teodutu November 15, 2023 07:23
Copy link

@teodutu teodutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @razvang0307. I made an inline suggestion, but before addressing that, please tell why this is needed. More recent GCC versions (11 and above for sure, maybe even lower) link lpthread by default.

Does linking cause errors on your system? If so, what GCC and linker versions are you using? Run gcc --version and ld --version and paste the first line of the outputs here.

@razvang0307 razvang0307 requested a review from teodutu November 16, 2023 08:06
@razvang0307
Copy link
Author

Hello.

Does linking cause errors on your system? If so, what GCC and linker versions are you using? Run gcc --version and ld --version and paste the first line of the outputs here.

gcc: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
ld: GNU ld (GNU Binutils for Ubuntu) 2.34

Attempting to run make in the directory outputs the following error:

/usr/bin/ld: sum_array_threads.o: in function `main':
/home/student/git/operating-systems/content/chapters/compute/lab/support/sum-array-bugs/seg-fault/sum_array_threads.c:97: undefined reference to `pthread_create'
/usr/bin/ld: /home/student/git/operating-systems/content/chapters/compute/lab/support/sum-array-bugs/seg-fault/sum_array_threads.c:105: undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make: *** [<builtin>: sum_array_threads] Error 1

The same happens if when appending -lpthread to LDFLAGS, however both -lpthread and -pthread seem to work for LDLIBS.

The environment in which I worked/tested was the qcow2/ARM virtual machine), which was posted on Teams as an answer to the first question on the "Technical Support" channel of the Operating Systems team, emulated via qemu on a native Linux computer.

I don't see any reason for the Makefile to be dependant on what gcc version you have, and there would be no harm in ensuring that the lpthread is linked by default.

@teodutu
Copy link

teodutu commented Nov 16, 2023

I don't see any reason for the Makefile to be dependant on what gcc version you have, and there would be no harm in ensuring that the lpthread is linked by default.

Yup, you're right. And thanks for the info about your system, now it makes more sense.

To merge this, please squash the 2 commits and then add a summary of the problem that this commit is solving to the commit description (such as "GCC 9.3 doesn't link against libpthread by default, so setting LDLIBS accordingly is required").

To do so, pull the latest commit to your local branch with git pull, then run git rebase -i HEAD~2. This will open a menu with the latest 2 commits. Change the word pick in front of the second one to s (from "squash") and then save and exit. You will be prompted to rewrite the first commit message. Add the description I mentioned above, keep the Signed-off-by line, and then save and exit again. After this, run git push -f to update the remote repo and it should be good to go.

accordingly is required

Signed-off-by: Razvan Gabriel <[email protected]>
@razvang0307
Copy link
Author

The commits have been squashed, thank you for providing the necessary commands and for guiding me through this process.

@teodutu teodutu merged commit 00910f5 into cs-pub-ro:main Nov 19, 2023
2 of 3 checks passed
@teodutu teodutu added the student-contrib Fix or improvement made by a student label Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code Update or new source code support / solution files kind/improve Improve / Update existing content / item student-contrib Fix or improvement made by a student topic/compute Related to "Compute" chapter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants