Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: CMAKE Building library like SFML  (Read 1749 times)

0 Members and 1 Guest are viewing this topic.

Doodlemeat

  • Guest
CMAKE Building library like SFML
« on: July 13, 2014, 08:47:58 pm »
When I build SFML with CMake I receive both .dll and .lib files. This is what I want to do with an own library I am working on but I can't get it to work. Currently only the .dll files are being generated.

This is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
set(project_name dxm)
project(dxm)

file(GLOB source_files "src/*.cpp")
file(GLOB include_files "include/DXM/*.hpp")

add_library(dxm SHARED ${include_files} ${source_files})

My directory tree looks like this
include/
        DXM/
                Math.hpp
                Config.hpp
src/
        Math.cpp
CMakeLists.txt

Math.hpp
#include "Config.hpp"

namespace dxm
{
        int DXM_API random(int min, int max);
}

Math.cpp
#include "Math.h"

namespace dxm
{
        int random(int min, int max)
        {
                return 3;
        }
}
Config.hpp
#pragma once

#define DMX_API __declspec(dllexport)

Why is only a .dll file being generated and not .lib?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMAKE Building library like SFML
« Reply #1 on: July 13, 2014, 08:55:05 pm »
This has nothing to do with SFML, you would have better / faster answers on a forum dedicated to CMake or general C++/build questions.

Usually, the .lib file is not created when the code exports no symbol. But nothing seems wrong in what you show, your function is correctly declared as __declspec(dllexport). What compiler do you use?
Laurent Gomila - SFML developer

Doodlemeat

  • Guest
Re: CMAKE Building library like SFML
« Reply #2 on: July 13, 2014, 09:02:44 pm »
I like the SFML overall because it can help me in general with programming questions and therefore I placed it here in a non-sfml help group. It also feels like after watching some threads at theirs forum, that they think one has worked with these things before.
This is my first time using CMake to create a project.

I use the compiler that came in Visual Studio 2013.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMAKE Building library like SFML
« Reply #3 on: July 13, 2014, 09:54:44 pm »
Found it. Your header is named Math.hpp, you include Math.h (which is valid since math.h is a standard header and Windows is case insensitive). So the compiler never sees the function declaration with the __declspec(dllexport) attribute.

Quote
I like the SFML overall because it can help me in general with programming questions
Although we don't strictly disallow them, and still try our best to answer when they are posted, we'd like to avoid such non-SFML questions on this forum.
« Last Edit: July 13, 2014, 09:57:30 pm by Laurent »
Laurent Gomila - SFML developer

Doodlemeat

  • Guest
Re: CMAKE Building library like SFML
« Reply #4 on: July 14, 2014, 12:24:19 am »
Thx! That did it! :)

Is it because the question is related to a third-party program? Because the forum description says "Help requests that are not related to a specific module". I would think it is good that these question are asked here too.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: CMAKE Building library like SFML
« Reply #5 on: July 14, 2014, 06:40:08 am »
Is it because the question is related to a third-party program? Because the forum description says "Help requests that are not related to a specific module". I would think it is good that these question are asked here too.
This is how many people misunderstand the purpose of this sub-forum. The other sub-forums are dedicated to a specific module, graphics, networking, window etc. For general SFML related questions like building, linking, etc. there is this sub-forum. This is why negation is powerful and very dangerous in mathematical theory and should never be used by itself or as the first predicate (think database queries as well). It can blow a set of objects up to unimaginable sizes ::).
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CMAKE Building library like SFML
« Reply #6 on: July 14, 2014, 10:01:14 am »
I'll leave the description as it is though, to avoid seeing all these non-SFML questions moving to "General > General Discussions" ;)
Laurent Gomila - SFML developer

 

anything