building a simple shared object library

General questions regarding the usage of CodeLite
swiz_ohio
CodeLite Curious
Posts: 3
Joined: Thu Mar 02, 2017 10:26 pm
Genuine User: Yes
IDE Question: c++
Contact:

building a simple shared object library

Post by swiz_ohio »

I have a very simple "hello World" type of application where I am prototyping using a shared object library (.so) . I can get the .so to compile fine, but the executable cannot find the shared library. What am I doing wrong ?

/bin/sh -c '/usr/bin/make -j8 -e -f "sharedTest.mk" MakeIntermediateDirs && /usr/bin/make -j8 -e -f "sharedTest.mk" all'
----------Building project:[ sharedTest - Debug ]----------
/usr/bin/g++ -o ./Debug/sharedTest @"sharedTest.txt" -L. -L/home/Steve/Documents/Codelitetest/sharedObj/Debug -L./Debug -lsharedObj
/usr/bin/ld: cannot find -lsharedObj
collect2: error: ld returned 1 exit status
sharedTest.mk:76: recipe for target 'Debug/sharedTest' failed
make: *** [Debug/sharedTest] Error 1
====0 errors, 0 warnings====

Code: Select all

##
## Auto Generated makefile by CodeLite IDE
## any manual changes will be erased      
##
## Debug
ProjectName            :=sharedTest
ConfigurationName      :=Debug
WorkspacePath          :=/home/steve/Documents/Codelitetest
ProjectPath            :=/home/steve/Documents/Codelitetest/sharedTest
IntermediateDirectory  :=./Debug
OutDir                 := $(IntermediateDirectory)
CurrentFileName        :=
CurrentFilePath        :=
CurrentFileFullPath    :=
User                   :=Steve Wisnieski
Date                   :=02/03/17
CodeLitePath           :=/home/steve/.codelite
LinkerName             :=/usr/bin/g++
SharedObjectLinkerName :=/usr/bin/g++ -shared -fPIC
ObjectSuffix           :=.o
DependSuffix           :=.o.d
PreprocessSuffix       :=.i
DebugSwitch            :=-g 
IncludeSwitch          :=-I
LibrarySwitch          :=-l
OutputSwitch           :=-o 
LibraryPathSwitch      :=-L
PreprocessorSwitch     :=-D
SourceSwitch           :=-c 
OutputFile             :=$(IntermediateDirectory)/$(ProjectName)
Preprocessors          :=
ObjectSwitch           :=-o 
ArchiveOutputSwitch    := 
PreprocessOnlySwitch   :=-E
ObjectsFileList        :="sharedTest.txt"
PCHCompileFlags        :=
MakeDirCommand         :=mkdir -p
LinkOptions            :=  
IncludePath            :=  $(IncludeSwitch). $(IncludeSwitch). 
IncludePCH             := 
RcIncludePath          := 
Libs                   := $(LibrarySwitch)sharedObj 
ArLibs                 :=  "sharedObj" 
LibPath                := $(LibraryPathSwitch). $(LibraryPathSwitch)/home/Steve/Documents/Codelitetest/sharedObj/Debug $(LibraryPathSwitch)$(IntermediateDirectory) 

##
## Common variables
## AR, CXX, CC, AS, CXXFLAGS and CFLAGS can be overriden using an environment variables
##
AR       := /usr/bin/ar rcu
CXX      := /usr/bin/g++
CC       := /usr/bin/gcc
CXXFLAGS :=  -g -O0 -Wall $(Preprocessors)
CFLAGS   :=  -g -O0 -Wall $(Preprocessors)
ASFLAGS  := 
AS       := /usr/bin/as


##
## User defined environment variables
##
CodeLiteDir:=/usr/share/codelite
Objects0=$(IntermediateDirectory)/main.c$(ObjectSuffix) 



Objects=$(Objects0) 

##
## Main Build Targets 
##
.PHONY: all clean PreBuild PrePreBuild PostBuild MakeIntermediateDirs
all: $(OutputFile)

$(OutputFile): $(IntermediateDirectory)/.d $(Objects) 
	@$(MakeDirCommand) $(@D)
	@echo "" > $(IntermediateDirectory)/.d
	@echo $(Objects0)  > $(ObjectsFileList)
	$(LinkerName) $(OutputSwitch)$(OutputFile) @$(ObjectsFileList) $(LibPath) $(Libs) $(LinkOptions)

MakeIntermediateDirs:
	@test -d ./Debug || $(MakeDirCommand) ./Debug


$(IntermediateDirectory)/.d:
	@test -d ./Debug || $(MakeDirCommand) ./Debug

PreBuild:


##
## Objects
##
$(IntermediateDirectory)/main.c$(ObjectSuffix): main.c $(IntermediateDirectory)/main.c$(DependSuffix)
	$(CC) $(SourceSwitch) "/home/steve/Documents/Codelitetest/sharedTest/main.c" $(CFLAGS) $(ObjectSwitch)$(IntermediateDirectory)/main.c$(ObjectSuffix) $(IncludePath)
$(IntermediateDirectory)/main.c$(DependSuffix): main.c
	@$(CC) $(CFLAGS) $(IncludePath) -MG -MP -MT$(IntermediateDirectory)/main.c$(ObjectSuffix) -MF$(IntermediateDirectory)/main.c$(DependSuffix) -MM main.c

$(IntermediateDirectory)/main.c$(PreprocessSuffix): main.c
	$(CC) $(CFLAGS) $(IncludePath) $(PreprocessOnlySwitch) $(OutputSwitch) $(IntermediateDirectory)/main.c$(PreprocessSuffix) main.c


-include $(IntermediateDirectory)/*$(DependSuffix)
##
## Clean
##
clean:
	$(RM) -r ./Debug/


User avatar
eranif
CodeLite Plugin
Posts: 6146
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: building a simple shared object library

Post by eranif »

Simple, you need to tell the linker where the shared object is.
You can do this from: Project Settings->Linker->Library Path

Eran
Make sure you have read the HOW TO POST thread
swiz_ohio
CodeLite Curious
Posts: 3
Joined: Thu Mar 02, 2017 10:26 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: building a simple shared object library

Post by swiz_ohio »

I did that, it still can't find it.
swiz_ohio
CodeLite Curious
Posts: 3
Joined: Thu Mar 02, 2017 10:26 pm
Genuine User: Yes
IDE Question: c++
Contact:

Re: building a simple shared object library

Post by swiz_ohio »

even when i go from command line it fails

steve@steve-G10AJ ~/Documents/Codelitetest/sharedTest $ gcc -L./Home/Steve/Documents/Codelitetest/sharedObj/Debug -Wall -o sharedTest main.c -lsharedOj
DavidGH
CodeLite Plugin
Posts: 706
Joined: Wed Sep 03, 2008 7:26 pm
Contact:

Re: building a simple shared object library

Post by DavidGH »

Hi,
steve@steve-G10AJ ~/Documents/Codelitetest/sharedTest $ gcc -L./Home/Steve/Documents/Codelitetest/sharedObj/Debug -Wall -o sharedTest main.c -lsharedOj
If you're 1) using a case-sensitive OS like Linux 2) that's cut/paste of your compile line, and 3) you don't have an unusual mountpoint, then:

Shouldn't "-L./Home/Steve/Documents/Codelitetest/sharedObj/Debug" be:
-L/home/Steve/Documents/Codelitetest/sharedObj/Debug
i.e. lowercase 'Home', and -L/ not -L./

Regards,

David
Post Reply