Hi,
I've been recently trying to compile my code for Linux and I'm running into some problems.
First of all, the code compiles fine & dandy, the trouble I'm having is related to the linking.
Most problems I have had in the past with linux have came down to the linking, where I would compile a binary one one box, it would work on that box, and fail miserably once it was moved to another box, and I learned to use "ldd" to check to see if bad stuff will happen.
I'm using the basic makefile for a sourcemm plugin, which is slightly modified, but generally identicle:
Code:
#(C)2004-2006 SourceMM Development Team
# Makefile written by David "BAILOPAN" Anderson
HL2SDK = ../Source
SMM_ROOT = ..
SRCDS = ../../srcds_l
### EDIT BELOW FOR OTHER PROJECTS ###
OPT_FLAGS = -O3 -funroll-loops -s -pipe
GCC4_FLAGS = -fvisibility=hidden -fvisibility-inlines-hidden
DEBUG_FLAGS = -g -ggdb3
CPP = gcc
BINARY = FortressAdmin_i486.so
OBJECTS = bitbuf.cpp\
CAdminCommands.cpp\
CEntity.cpp\
CMySQL.cpp\
CPlayer.cpp\
CServerData.cpp\
CUsers.cpp\
CUtil.cpp\
cvars.cpp\
CWeapon.cpp\
EntityList.cpp\
entitylist_base.cpp\
EventHook.cpp\
IceKey.cpp\
MessageHook.cpp\
ORecipientFilter.cpp\
VFuncs.cpp\
WeaponMod.cpp\
CThreads.cpp\
FortressAdmin.cpp
HL2PUB = $(HL2SDK)/public
HL2LIB = $(HL2SDK)/linux_sdk
LINK = $(HL2LIB)/tier1_i486.a vstdlib_i486.so tier0_i486.so -static-libgcc
INCLUDE = -I. -I.. \
-I$(HL2PUB) \
-I$(HL2PUB)/dlls \
-I$(HL2PUB)/engine \
-I$(HL2PUB)/tier0 \
-I$(HL2PUB)/tier1 \
-I$(HL2PUB)/vstdlib \
-I$(HL2SDK)/dlls \
-I$(HL2SDK)/game_shared \
-I$(HL2SDK)/tier1 \
-I$(SMM_ROOT) \
-I$(SMM_ROOT)/sourcehook \
-I$(SMM_ROOT)/sourcemm \
-I ./MySQL
ifeq "$(DEBUG)" "true"
BIN_DIR = Debug
CFLAGS = $(DEBUG_FLAGS)
else
BIN_DIR = Release
CFLAGS = $(OPT_FLAGS)
endif
GCC_VERSION := $(shell $(CPP) -dumpversion >&1 | cut -b1)
CFLAGS += -D_LINUX -DNDEBUG -Dstricmp=strcasecmp -D_stricmp=strcasecmp -D_strnicmp=strncasecmp -Dstrnicmp=strncasecmp -D_snprintf=snprintf -D_vsnprintf=vsnprintf -D_alloca=alloca -Dstrcmpi=strcasecmp -Wall -w -Wno-non-virtual-dtor -fPIC -fno-exceptions -msse -msse2
ifeq "$(GCC_VERSION)" "4"
CFLAGS += $(GCC4_FLAGS)
endif
OBJ_LINUX := $(OBJECTS:%.cpp=$(BIN_DIR)/%.o)
$(BIN_DIR)/%.o: %.cpp
$(CPP) $(INCLUDE) $(CFLAGS) -o $@ -c $<
all:
mkdir -p $(BIN_DIR)
ln -sf $(SRCDS)/bin/vstdlib_i486.so vstdlib_i486.so
ln -sf $(SRCDS)/bin/tier0_i486.so tier0_i486.so
$(MAKE) sourcemm
rm -rf $(BINARY)
ln -sf $(BIN_DIR)/$(BINARY) $(BINARY)
sourcemm: $(OBJ_LINUX)
$(CPP) $(INCLUDE) $(CFLAGS) $(OBJ_LINUX) $(LINK) -shared -ldl -lm -o$(BIN_DIR)/$(BINARY)
debug:
$(MAKE) all DEBUG=true
default: all
clean:
rm -rf Release/*.o
rm -rf Release/$(BINARY)
rm -rf Debug/*.o
rm -rf Debug/$(BINARY)
Once it's compiled, I perform an ldd on the binary and I'm greeted with this:
Code:
linux-gate.so.1 => (0x0065a000)
vstdlib_i486.so => not found
tier0_i486.so => not found
libdl.so.2 => /lib/libdl.so.2 (0x00789000)
libm.so.6 => /lib/libm.so.6 (0x0022b000)
libc.so.6 => /lib/libc.so.6 (0x00254000)
/lib/ld-linux.so.2 (0x80000000)
All of the paths to the SDK, srcds are of course, correct.
This is on a linux box with Federa Core 7, and some variation of GCC 4 (thinking GCC4.1 but could be mistaken)
Obviously, I'm still doing something wrong, any ideas what it could be?