cs50 / libcs50

This is CS50's Library for C.
https://cs50.readthedocs.io/libraries/cs50/c/
GNU General Public License v3.0
1.74k stars 853 forks source link

Makefile with inconsistent library name (VERSION vs. MAJOR) #146

Closed Blauelf closed 5 years ago

Blauelf commented 5 years ago

In the Makefile of 8.1.2, there's

$(LIBS): $(SRC) $(INCLUDE) Makefile
    $(CC) $(CFLAGS) -fPIC -shared $(LINKER_FLAGS) -o $(LIB_VERSION) $(SRC)
    ln -sf $(LIB_MAJOR) $(LIB_BASE)
    mkdir -p $(addprefix build/, include lib src)
    install -m 644 $(SRC) build/src
    install -m 644 $(INCLUDE) build/include
    mv $(LIB_VERSION) $(LIB_BASE) build/lib

If I read it correctly, this builds $(LIB_VERSION), but in the next step creates a link to $(LIB_MAJOR) (which wasn't built in the step before).

kzidane commented 5 years ago

@Blauelf $(LIB_MAJOR) should be automatically created by ldconfig when you make install.

Blauelf commented 5 years ago

Not sure if I just don't understand makefiles correctly, but does $(LIB_MAJOR) exist at the time this command is run, and even if I start make without any compiled files?

Blauelf commented 5 years ago

Oh, apparently, I am misunderstanding symbolic links. They work fine even if the target does not exist.

Still, there is a target /build/lib/$(LIB_MAJOR) that is not created in that step, is that the way it is meant?

kzidane commented 5 years ago

@Blauelf yes, unless you're doing a make install, you shouldn't be using $(LIB_MAJOR) directly.

Blauelf commented 5 years ago

But ldconfig does not seem to create that one. After a make install, I get two files in /usr/local/lib/:

-rwxr-xr-x 1 root root 21736 Nov 20 23:44 libcs50.so.8.1.2
lrwxrwxrwx 1 root root    12 Nov 20 23:44 libcs50.so -> libcs50.so.8

The link libcs50.so.8 -> libcs50.so.8.1.2 is missing.

kzidane commented 5 years ago

Hmm, which Linux distro are you using? Does it work if you do ldconfig /usr/local/lib?

Blauelf commented 5 years ago

Tried on arch linux. And yes, that last version with path works, creating the link. Seems like that linux distro does not list /usr/local/lib in /etc/ld.so.conf.d/* or $LD_LIBRARY_PATH, meaning neither linking nor execution works out of the box.

kzidane commented 5 years ago

I see. I'm gonna fix shortly. Thank you!

Blauelf commented 5 years ago

I think it's more an issue with arch Linux discouraging usage of /usr/local. Not sure why they do. So to use the library when it is installed in /usr/local/lib, the user always has to adjust something on their system, even if it installed there properly.

cmlsharp commented 5 years ago

Apologies for the delayed response, I just saw this. I also use Arch.

Configuring where libcs50 gets installed is what DESTDIR is for in the Makefile. If you run sudo DESTDIR=/usr/lib make install, it will install into /usr/lib. It may make sense to make /usr/lib be the default on linux.

kzidane commented 5 years ago

147

Blauelf commented 5 years ago

Thanks both of you for all that information.