Fix some bugs related to dynamic linking