Linux, C++, Lua 5.3, CMake, undefined reference
<p>I'm trying to use Lua in my C++ program. My OS is Linux Manjaro 15.12. I downloaded the Lua 5.3 source code, and compiled it as C++ code (I really need the exception handling instead of longjmp), with this line:</p>

<pre><code>make "CC=g++" linux
</code></pre>

<p>Then <em>sudo make install</em> to get Lua installed in /usr/local. Everything looks fine. My CMake version seems to be updated:</p>

<pre><code>cmake --version
cmake version 3.4.1
</code></pre>

<p>In my CMake file, I find Lua like this:</p>

<pre><code>find_package(Lua REQUIRED)
include_directories(${LUA_INCLUDE_DIR})

message("   *** Lua include: ${LUA_INCLUDE_DIR}")
message("   *** Lua lib: ${LUA_LIBRARIES}")
</code></pre>

<p>After running this command:</p>

<pre><code>cd build
cmake -G "Unix Makefiles" ..
</code></pre>

<p>The include folder is properly detected in /usr/local/include, but the library itself, is found as /usr/lib64/liblua5.1.so;/usr/lib64/libm.so, wich is not the installation I did (and its version 5.1, I want 5.3). CMake says:</p>

<pre><code>Found Lua: /usr/lib64/liblua5.1.so;/usr/lib64/libm.so (found version "5.3.2")
</code></pre>

<p>Its like it is "mixing" the two versions. Running <em>make</em> throws a lot of undefined references. Previously in my CMake file, I find other libraries (SDL2 compiled by me, OpenGL, glew), and they seem to work. The only errors I got are for the Lua library. Of course, I'm adding the libraries to my <em>target_link_libraries</em> command</p>

<p>How can I fix this? (I don't care if I have to eliminate the older Lua version, as long as it doesn't break my OS).</p>