I have this target that compiles ok.
#
file(GLOB SOURCE_FILES
8021QBG/*.h
8021QBG/*.cpp
)
add_library(8021qbg SHARED
${SOURCE_FILES}
)
set_target_properties(8021qbg PROPERTIES LINKER_LANGUAGE CXX)
set(CMAKE_CXX_FLAGS_CUSTOM " ")
set_target_properties(8021qbg PROPERTIES COMPILE_FLAGS " ${CMAKE_CXX_FLAGS_CUSTOM} ${CMAKE_CXX_FLAGS_COMMON}")
add_dependencies(8021qbg core )
target_link_libraries(8021qbg -L${PROJECT_BINARY_DIR})
target_link_libraries(8021qbg -L/home/user/protocol_so )
target_link_libraries(8021qbg -L${PROJECT_SOURCE_DIR}/lib64 )
target_link_libraries(8021qbg -L${PROJECT_SOURCE_DIR})
target_link_libraries(8021qbg protocol_common thread vip core m xml2)
target_include_directories(8021qbg PUBLIC
8021QBG
nte-encap
)
and this that fails.
#
file(GLOB SOURCE_FILES
Agent/*.h
Agent/*.cpp
)
add_library(agent SHARED
${SOURCE_FILES}
)
set_target_properties(agent PROPERTIES LINKER_LANGUAGE CXX)
set(CMAKE_CXX_FLAGS_CUSTOM " ")
set_target_properties(agent PROPERTIES COMPILE_FLAGS " ${CMAKE_CXX_FLAGS_CUSTOM} ${CMAKE_CXX_FLAGS_COMMON}")
add_dependencies(agent core)
target_link_libraries(agent -L${PROJECT_BINARY_DIR})
target_link_libraries(agent -L/home/user/protocol_so )
target_link_libraries(agent -L${PROJECT_SOURCE_DIR}/lib64 )
target_link_libraries(agent -L${PROJECT_SOURCE_DIR})
target_link_libraries(agent protocol_common thread vip core xml2 pthread)
target_include_directories(agent PUBLIC
Agent
nte-encap
)
Also these targets have the same flags:
set (CMAKE_CXX_FLAGS_COMMON "-g -fpermissive -std=gnu89 -Wall -O0 -m64 -fPIC -DLINUX -DCPU_64 -DXSTREAM ")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--unresolved-symbols=ignore-in-shared-libs -shared -Wl,-rpath,/home/user/protocol_so:/home/user/cmake_libs/lib64:libwifi")
if(NOT CMAKE_CXX_CREATE_SHARED_LIBRARY)
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
"<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
endif()
This is linker stage
/usr/bin/g++ -fPIC -g -Wl,--unresolved-symbols=ignore-in-shared-libs -shared -Wl,-rpath,/home/user/protocol_so:/home/user/cmake_libs/lib64:libwifi -shared -Wl,-soname,libagent.so -o libagent.so CMakeFiles/agent.dir/Agent/agent_common.cpp.o CMakeFiles/agent.dir/Agent/agent_main.cpp.o CMakeFiles/agent.dir/Agent/agent_client.cpp.o CMakeFiles/agent.dir/Agent/agent_cmd.cpp.o CMakeFiles/agent.dir/Agent/agent_go.cpp.o -L/home/user/cmake_libs/cmake-build-debug-rurem -L/home/user/protocol_so -L/home/user/cmake_libs/lib64 -L/home/user/cmake_libs -lprotocol_common -lthread -lvip libcore.so -lxml2 -lpthread -L/home/user/cmake_libs/lib64 -lprotocol_common -lthread -lvip -lcrypto -lglib-2.0 -lm -lxml2 -lpthread -Wl,-rpath,/home/user/cmake_libs/cmake-build-debug-rurem
This is error codes
/home/user/cmake_libs/Agent/agent_main.cpp:47: undefined reference to `agent_client_register'
/home/user/cmake_libs/Agent/agent_main.cpp:48: undefined reference to `agent_client_unregister'
/home/user/cmake_libs/Agent/agent_main.cpp:49: undefined reference to `agent_client_register_task'
/home/user/cmake_libs/Agent/agent_main.cpp:50: undefined reference to `agent_client_unregister_task'
Cmake compiles each *.cpp file to *.o object and than linker combine them in one *.so lib -> in the linker stage I got this error.
Sources located in "Agent" folder and I add it to the target 'agent'.
UDP>
simple makefile and GCC build this library.
makefile part:
libagent.so: ${wildcard Agent/*.[c,h]} libcore.so
$(CC) $(CFLAGS) -fPIC -shared -o $# $(filter %.c,$^) $(IPATH) $(RPATH) $(TE_VIP) -lcore -lxml2 -lpthread
gcc command
gcc -g -Wall -O0 -m64 -Wl,--unresolved-symbols=ignore-in-shared-libs -fPIC -shared -o libagent.so -Inte-include -Ixst_inc -Ixst_tls -L./lib64 -L./cmake-build-debug-rurem -Wl,-rpath,/home/user/protocol_so:/home/user/lib64:libwifi -DLINUX -DCPU_64 -DXSTREAM -lprotocol_common -lthread -lvip -lcore -lxml2 -lpthread
UDP#2.
on arm machine with gcc v9.1.0 it builds successfully via makefile.
on x86 machine with gcc v4.3.4 I have such undefined referencies.
this is compiling command
g++ -g -Wall -O0 -m64 -Wl,--unresolved-symbols=ignore-in-shared-libs -fPIC -shared -o 0libagent.so -Inte-include -Iinc -Itls -L/home/user/cmake_libs/lib64 -L/home/user/cmake_libs -Wl,-rpath,/home/user/protocol_so:/home/user/cmake_libs/lib64:libwifi -DLINUX -DCPU_64 -DXSTREAM -lprotocol_common -lthread -lvip -lcore -lxml2 -lpthread Agent/agent_main.cpp Agent/agent_cmd.cpp Agent/agent_client.cpp Agent/agent_go.cpp Agent/agent_common.cpp
This is piece of agent_main.cpp that causes errors:
This is function that defined in agent_client.cpp that causes undefined reference
UPD#3
nm says that definitions are in objects.
> nm CMakeFiles/agent.dir/Agent/agent_client.cpp.o
...
00000000000007e2 T _Z21agent_client_registeriP20_protocol_callback_t
0000000000000000 T _Z21agent_client_run_taskiPv
0000000000000033 T _Z22agent_client_do_actionPviS_S_
...
x86 machine - SUSE 11 sp3 x64
Why it fails?
How to fix it?
The main point was not in cmake, and even not in make commands. I think this is about gcc versions support. On x86 I have gcc v4.3.4.
As #AlexCohn said in the comments
I would try to declare agent_client_register() and the rest of them as
extern "C" in agent_client.h and make sure this header is included in
both agent_client.cpp and agent_main.cpp
Related
I know that these are required to compile a C++ app but what I don't know is how do I build my app so that other users won't need them. I tried to use -static flags to build but it still won't work when I remove mingw\bin\ and msys2\usr\bin\ from my path or when my friends who don't have a C++ compiler try to run it. For the record, I did include every library for the project when I asked for friends to run it.
Here's my Makefile :
rtx.exe: base.o objects.o rtx.o
g++ -O3 base.o objects.o rtx.o -o rtx -pthread -Lsrc\lib -lsfml-graphics -lsfml-window -lsfml-system -ljsoncpp -static -static-libgcc -static-libstdc++
rtx.o: rtx.cpp
g++ -Isrc\include -O3 -c rtx.cpp -static -static-libgcc -static-libstdc++
objects.o: objects.cpp objects.hpp
g++ -Isrc\include -O3 -c objects.cpp -static -static-libgcc -static-libstdc++
base.o: base.cpp base.hpp
g++ -Isrc\include -O3 -c base.cpp -static -static-libgcc -static-libstdc++
clean:
-rm *.o $(objects) rtx.exe
And here's one of the pop-op I (and my friends withour a C++ compiler) get :
There are 4 pop-ups, 2 of them being this one and the other says the same thing for libstdc++-6.dll.
I tried a bunch of things, including compiling objects.o and base.o into a library using the ar ru command but it gives the same pop-ups.
My guess is that one of the libraries I'm using, either jsonCpp or SFML is not built statically, but I couldn't find anything about how to fix it.
If you want to get rid of shared runtime libraries, you have to ensure that all your dependencies have linked the runtime statically.
SFML is by default not built with static runtime libraries, so you'll certainly have to rebuild SFML with SFML_USE_STATIC_STD_LIBS set in CMake. Similarly I assume for jsoncpp.
So, as advised by HolyBlackCat, I fully reinstalled MSYS2 and downloaded SFML and jsonCpp with mingw and after a bit of research and trial and error I ended up with this makeFile :
rtx.exe: base.o objects.o rtx.o
g++ -O3 base.o objects.o rtx.o -o rtx -pthread -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -ljsoncpp -static
rtx.o: rtx.cpp
g++ -Isrc\include -O3 -c rtx.cpp -DSFML_STATIC -static
objects.o: objects.cpp objects.hpp
g++ -Isrc\include -O3 -c objects.cpp -DSFML_STATIC -static
base.o: base.cpp base.hpp
g++ -Isrc\include -O3 -c base.cpp -DSFML_STATIC -static
clean:
-rm *.o $(objects) rtx.exe
And now, it does make a static build.
I tried to use -rdynamic option in my CMakeLists.txt file, like this:
cmake_minimum_required(VERSION 3.5)
project(Tmuduo CXX)
...
set(CMAKE_CXX_STANDARD 11)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Wthread-safety )
endif()
add_compile_options(
# -DVALGRIND
-Wall
-Wno-unused-parameter
-Woverloaded-virtual
-Wpointer-arith
-Wwrite-strings
-O3
-rdynamic
)
...
When I use cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang and make VERBOSE=1, I got some message as follow:
Just as you can see, the -rdynamic compile option did appear in the clang++ command and the compiler also complainted that the argument was unused. But when I used the command below, something strange happended.
clang++ -I/home/phoenix/MyProject/Tmuduo -g -Wthread-safety -Wall -Wno-unused-parameter -Woverloaded-virtual -Wpointer-arith -Wwrite-strings -rdynamic -std=gnu++11 test/Exception_test.cc base/Exception.cc base/CurrentThread.cc -o exception_test -O3
Everything goes well. This time, the -rdynamic option works. That reall make me confuse. Can anyone tell me what's going on here? Why the clang++ command works while the cmake failed?
Because -rdynamic is a linker option, so if you use when compiling a source file into an object *.o it does nothing, there is no link phase here.
When linking all the *.o and libraries into the finally executable, then it is actually used.
From man gcc (but clang uses the same):
-rdynamic
Pass the flag -export-dynamic to the ELF linker, on targets that support it.
This instructs the linker to add all symbols, not only used ones, to the
dynamic symbol table. This option is needed for some uses of "dlopen" or to
allow obtaining backtraces from within a program.
I am trying to use CLion to work with IBM ILOG CPLEX 12.7.1 on my Mac OS 10.13.1 (macOS High Sierra). Here is a very simple piece of C++ code.
#include <iostream>
#include <ilcplex/ilocplex.h>
using namespace std;
int main() {
std::cout << "Hello, World!" << std::endl;
IloEnv env;
x: IloCplex cplex(env);
std::cout << env.getVersion() << endl;
return 0;
}
The following in my Makefile.
SYSTEM = x86-64_osx
LIBFORMAT = static_pic
CPLEXDIR = /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex
CONCERTDIR = /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/concert
# ---------------------------------------------------------------------
# Compiler selection
# ---------------------------------------------------------------------
CCC = clang++ -O0
# ---------------------------------------------------------------------
# Compiler options
# ---------------------------------------------------------------------
CCOPT = -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -stdlib=libc++
# ---------------------------------------------------------------------
# Link options and libraries
# ---------------------------------------------------------------------
CPLEXBINDIR = $(CPLEXDIR)/bin/$(BINDIST)
CPLEXLIBDIR = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CONCERTLIBDIR = $(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CCLNDIRS = -L$(CPLEXLIBDIR) -L$(CONCERTLIBDIR)
CCLNFLAGS = -lconcert -lilocplex -lcplex -lm -lpthread -ldl #-framework CoreFoundation -framework IOKit -stdlib=libc++
all:
make main
CONCERTINCDIR = $(CONCERTDIR)/include
CPLEXINCDIR = $(CPLEXDIR)/include
CCFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR)
# ------------------------------------------------------------
main: main.o
$(CCC) $(CCFLAGS) $(CCLNDIRS) -o main main.o $(CCLNFLAGS)
main.o: ./main.cpp
$(CCC) -c $(CCFLAGS) ./main.cpp -o main.o
Here is the CMakeLists.txt, which I have tried to create it with parameters exactly as mentioned in the Makefile.
cmake_minimum_required(VERSION 3.14)
project(cplextest)
add_executable(cplextest main.cpp)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -stdlib=libc++")
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/include/)
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/include/ilcplex)
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/concert/include)
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/concert/include/ilconcert)
find_library(lib1 NAMES libcplex.a PATHS /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/lib/x86-64_osx/static_pic/)
find_library(lib2 NAMES libilocplex.a PATHS /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/lib/x86-64_osx/static_pic/)
find_library(lib3 NAMES libcplexdistmip.a PATHS /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/lib/x86-64_osx/static_pic/)
set (CMAKE_SHARED_LINKER_FLAGS "-lconcert -lilocplex -lcplex -lm -lpthread -ldl #-framework CoreFoundation -framework IOKit -stdlib=libc++")
target_link_libraries(cplextest PUBLIC ${lib1})
target_link_libraries(cplextest PUBLIC ${lib2})
target_link_libraries(cplextest PUBLIC ${lib3})
However, while Makefile works flawlessly (i.e., I can successfully run my program from a terminal), CLion produces the following error messages.
====================[ Build | cplextest | Debug ]===============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/soheilmn/CLionProjects/CplexTest/cmake-build-debug --target cplextest -- -j 2
[ 50%] Linking CXX executable cplextest
Undefined symbols for architecture x86_64:
"IloCplex::IloCplex(IloEnv)", referenced from:
_main in main.cpp.o
"IloCplexI::getVersion() const", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [cplextest] Error 1
make[2]: *** [CMakeFiles/cplextest.dir/all] Error 2
make[1]: *** [CMakeFiles/cplextest.dir/rule] Error 2
make: *** [cplextest] Error 2
Interestingly, if I comment out the line (x) in my C++ code, I can successfully run my code from CLion. This is indeed very confusing to me, because my understanding is both procedures use clang++ and the same libraries/header files. Any help will be highly appreciated. (Sorry for the long post in advance!)
Thanks!
CMAKE_SHARED_LINKER_FLAGS specifies flags to use when creating new shared libraries. But your project doesn't create shared libraries, it creates an executable. You should just pass all the library names to target_link_libraries like this:
target_link_libraries(cplextest PUBLIC "concert;cplex;ilocplex;cplexdistmip")
Then you may need to add the library search path (/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio1271/cplex/lib/x86-64_osx/static_pic/) and it should all work. Run make VERBOSE=1 after running cmake if you want to see what linker command is actually run.
To enable pthreads, see cmake and libpthread
Special thanks go to "John Zwinck" for his help. I thought it makes sense to share the final CMake file that perfectly works with IBM ILOG CPLEX 12.9 under macOS 10.13.1 / CLion 2109.2.3. Here it is:
cmake_minimum_required(VERSION 3.14)
project(cplextest)
add_executable(cplextest main.cpp)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -stdlib=libc++")
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/cplex/include/)
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/cplex/include/ilcplex)
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/concert/include)
include_directories(/Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/concert/include/ilconcert)
target_link_libraries(cplextest PUBLIC /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/cplex/lib/x86-64_osx/static_pic/libcplex.a)
target_link_libraries(cplextest PUBLIC /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/cplex/lib/x86-64_osx/static_pic/libilocplex.a)
target_link_libraries(cplextest PUBLIC /Users/soheilmn/Applications/IBM/ILOG/CPLEX_Studio129/concert/lib/x86-64_osx/static_pic/libconcert.a)
set (target_link_options "-lconcert -lilocplex -lcplex -lm -lpthread -ldl -framework CoreFoundation -framework IOKit -stdlib=libc++")
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I would like to ask how to convert Makefile to CMAKEList. Currently I can compile CMAKEList. However, the program doesn’t behave like the program generated out of Makefile program.
details:
1. This is my Makefile
#===========================================================================
# Makefile for behavior_program
#---------------------------------------------------------------------------
# [Update log]
#===========================================================================
TARGET = PFforAEV0.2.2
CC = g++
SYSTEM = linux
LIB_DIR = -L/usr/local/lib
#LIBS = -lglut -lGLU -lGL -lm -lX11 -lXi -L/usr/X11R6/lib -lpthread -lSSM
LIBS = -lm -L/usr/X11R6/lib -L/usr/local/lib64 -lpthread -lSSM
INCDIR = -I./include -I/usr/local/include
#DEBUG
CPPFLAGS= -O3 -Wall $(INCDIR)
#COMPLETE
#CFLAGS = -O2 -g -Wall -Werror -Wmissing-prototypes $(INCDIR)
OBJS = primitives.o PFforAEV.o motion_vw.o observation_lrf.o particle_filter.o gnuplot2D.o
all: $(SYSTEM)
linux: $(OBJS)
$(CC) $(OBJS) $(LIB_DIR) $(LIBS) -o $(TARGET)
rm -f *.o *~ defs/*~ core
clean:
rm -f $(TARGET) *.o *~ defs/*~ core
install:
cp $(TARGET) ../../bin
This is my CMAKEList
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(PFforAEV0.2.2)
include_directories( -I./include -I/usr/local/include)
include_directories(-I./include -I/usr/local/include)
add_executable(PFforAEV0.2.2 primitives.cpp PFforAEV.cpp motion_vw.cpp
observation_lrf.cpp particle_filter.cpp gnuplot2D.cpp)
target_link_libraries (PFforAEV0.2.2 -lm -L/usr/X11R6/lib -L/usr/local/lib64 -lpthread -lSSM -L/usr/local/lib)
set(CMAKE_CXX_FLAGS " -Wall -I./include -I/usr/local/include ")
From a quick look, your compile flags are not the same.
For example, in the Makefile you have
CPPFLAGS= -O3 -Wall $(INCDIR)
But, in CMakeLists.txt you have
set(CMAKE_CXX_FLAGS " -Wall -I./include -I/usr/local/include ")
which is missing the "-O3" flag.
Make sure the flags are identical.
The same goes for the linked libraries.
I just like to hint that there are some mechanisms/commands in CMake you could use to reduce your codes dependency on certain compiler options and installation environments:
cmake_minimum_required( VERSION 2.8 FATAL_ERROR )
project( PFforAEV0.2.2 C++ )
find_package( Threads )
include_directories(
include
usr/local/include
)
set(
inFiles
primitives.cpp
PFforAEV.cpp
motion_vw.cpp
observation_lrf.cpp
particle_filter.cpp
gnuplot2D.cpp
)
add_definitions(" -Wall -O3")
add_executable( PFforAEV0.2.2 ${inFiles} )
link_directories(
/usr/X11R6/lib
/usr/local/lib64
/usr/local/lib
)
target_link_libraries(
PFforAEV0.2.2
${CMAKE_THREAD_LIBS_INIT}
m
SSM
)
See also:
How do I force cmake to include "-pthread" option during compilation?
CMake:How To Find Libraries
How to set warning level in CMake?
You may not need all include or library search paths, because CMake also detects the environment e.g. by checking environments variables:
// see share/cmake-2.8/Modules/CMakeCommonLanguageInclude.cmake
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} $ENV{LDFLAGS}" CACHE STRING "Flags used by the linker.")
// see share/cmake-2.8/Modules/CMakeCXXInformation.cmake
set(CMAKE_CXX_FLAGS_INIT "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_INIT}")
And CMake does handle the different debug/optimization options for you in different build configs. E.g. GNU C++ defaults look like this:
set(CMAKE_CXX_FLAGS_INIT "")
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
I'm trying to build my openGL project, all worked well until I tried to use the SOIL library (http://www.lonesock.net/soil.html) for loading textures from images. This library comes with a SOIL.h and a libSOIL.a files.
That's what I get when doing make:
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/main.o src/main.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/file_ply_stl.o src/file_ply_stl.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/Proyecto.o src/Proyecto.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/Clock.o src/Clock.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/utils.o src/utils.cpp
...
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/primitives/cilindro.o src/primitives/cilindro.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -c -o src/primitives/cono.o src/primitives/cono.cpp
g++ -I./src -Wl,-rpath,./lib -O3 -g -o app -L./lib src/main.o src/file_ply_stl.o src/Proyecto.o src/Clock.o src/utils.o src/Window.o src/Light.o src/Material.o src/PlyModel.o src/Placeable.o src/Moveable.o src/Model.o src/Texture.o src/Geometry.o src/TriGeometry.o src/TriIndGeometry.o src/Entity.o src/Camera.o src/Bounded.o src/Animatable.o src/Scene.o src/Graphics.o src/Vert.o src/Path.o src/Ant.o src/Tank.o src/Chess.o src/primitives/tetra.o src/primitives/cubo.o src/primitives/cilindro.o src/primitives/cono.o -lsfml-window -lsfml-system -lX11 -lXext -lXmu -lXi -lXt -lSM -lICE -lGLU -lGL -lglut -lSOIL
src/Texture.o: In function `Texture::ini(char const*)':
/home/roger/t/ig/prac/proyecto/src/Texture.cpp:9: undefined reference to `SOIL_load_OGL_texture'
collect2: ld devolvió el estado de salida 1
make: *** [app] Error 1
And that's my Makefile:
TARGET = app
MODULES = src/main.o src/file_ply_stl.o src/Proyecto.o src/Clock.o src/utils.o
ENGINE = src/Window.o src/Light.o src/Material.o src/PlyModel.o src/Placeable.o src/Moveable.o src/Model.o src/Texture.o src/Geometry.o src/TriGeometry.o src/TriIndGeometry.o src/Entity.o src/Camera.o src/Bounded.o src/Animatable.o src/Scene.o src/Graphics.o src/Vert.o
GAME = src/Path.o src/Ant.o src/Tank.o
PRIMITIVES = src/Chess.o src/primitives/tetra.o src/primitives/cubo.o src/primitives/cilindro.o src/primitives/cono.o
CXX = g++
LIBDIR = ./lib
INCDIR = ./src
LIBS = -lsfml-window -lsfml-system -lX11 -lXext -lXmu -lXi -lXt -lSM -lICE -lGLU -lGL -lglut -lSOIL
LDFLAGS = -L$(LIBDIR)
CXXFLAGS = -I$(INCDIR) -Wl,-rpath,$(LIBDIR) -O3 -g
$(TARGET): $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES)
$(CXX) $(CXXFLAGS) -o $(TARGET) $(LDFLAGS) $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES) $(LIBS)
clean:
rm -f $(MODULES) $(ENGINE) $(GAME) $(PRIMITIVES) $(TARGET)
And that's my file hierachy:
.:
lib Makefile src
./lib:
libsfml-audio.so libsfml-graphics.so.2.0 libsfml-system.so.2 libSOIL.a
libsfml-audio.so.2 libsfml-network.so libsfml-system.so.2.0 libSOIL.a.1
libsfml-audio.so.2.0 libsfml-network.so.2 libsfml-window.so libSOIL.a.1.0
libsfml-graphics.so libsfml-network.so.2.0 libsfml-window.so.2
libsfml-graphics.so.2 libsfml-system.so libsfml-window.so.2.0
./src:
Animatable.cpp Clock.cpp Light.cpp Moveable.h random.h TriGeometry.h
Animatable.h Clock.h Light.h Path.cpp Scene.cpp TriIndGeometry.cpp
Ant.cpp Entity.cpp main.cpp Path.h Scene.h TriIndGeometry.h
Ant.h Entity.h main.h Placeable.cpp SFML utils.cpp
Bounded.cpp file_ply_stl.cpp Material.cpp Placeable.h SOIL utils.h
Bounded.h file_ply_stl.h Material.h PlyModel.cpp Tank.cpp Vert.cpp
Camera.cpp Geometry.cpp matrix.h PlyModel.h Tank.h vertex.h
Camera.h Geometry.h Model.cpp primitives Texture.cpp Vert.h
Chess.cpp Graphics.cpp Model.h Proyecto.cpp Texture.h Window.cpp
Chess.h Graphics.h Moveable.cpp Proyecto.h TriGeometry.cpp Window.h
./src/primitives:
...
./src/SFML:
...
./src/SFML/Audio:
...
./src/SFML/Graphics:
...
./src/SFML/Network:
...
./src/SFML/System:
...
./src/SFML/Window:
...
./src/SOIL:
SOIL.h
I don't know what's going on, and why the compiler doesn't find the library file.
I've got #include "SOIL/SOIL.h" in Texture.h and the call to SOIL_load_OGL_texture in Texture.cpp:9, that's the name on the function as defined in SOIL.h. ¿What I am doing bad?
EDIT
I was using the library provided, I compiled it myself and it worked.
I must write down this answer when I compile the SOIL library even the question is asked 4 year ago, because it is so hard to write the CMakeLists.txt myself before I find the CMakeLists.txt.
the CMakeLists.txt
cmake_minimum_required (VERSION 2.6)
project (SOIL)
set (SOIL_BUILD_TESTS false CACHE BOOL "Build tests")
if(ANDROID)
# Android requires GL ES 2.0 package automatically
set(LIBRARIES GLESv2)
else()
find_package (OpenGL REQUIRED)
include_directories (${OPENGL_INCLUDE_DIR})
set(LIBRARIES ${OPENGL_LIBRARIES})
endif()
file (GLOB SOIL_SOURCES src/*.c)
file (GLOB SOIL_HEADERS src/*.h)
add_library (SOIL ${SOIL_SOURCES} ${SOIL_HEADERS})
target_link_libraries (SOIL ${LIBRARIES})
install (TARGETS SOIL
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install (FILES ${SOIL_HEADERS} DESTINATION include/SOIL)
if (SOIL_BUILD_TESTS)
add_executable (test_SOIL src/test_SOIL.cpp)
target_link_libraries (test_SOIL SOIL)
install (TARGETS SOIL test_SOIL RUNTIME DESTINATION bin)
endif ()