Skip to content

Commit

Permalink
Merge pull request #2013 from STEllAR-GROUP/fixing_2011
Browse files Browse the repository at this point in the history
Fixing compilation issues with external example
  • Loading branch information
hkaiser committed Mar 6, 2016
2 parents e9730b5 + c3481ea commit 04fa126
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 101 deletions.
8 changes: 4 additions & 4 deletions cmake/HPX_GeneratePackage.cmake
Expand Up @@ -52,12 +52,12 @@ endforeach()

if(HPX_WITH_STATIC_LINKING)
set(HPX_CONF_LIBRARIES "hpx;${HPX_LIBRARIES}")
set(HPX_PKG_LIBRARIES "-lhpx ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "-lhpxd ${HPX_PKG_DEBUG_LIBRARIES}")
set(HPX_PKG_LIBRARIES "\${libdir}/libhpx.a ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "\${libdir}/libhpxd.a ${HPX_PKG_DEBUG_LIBRARIES}")
else()
set(HPX_CONF_LIBRARIES "hpx;hpx_init;${HPX_LIBRARIES}")
set(HPX_PKG_LIBRARIES "-lhpx -lhpx_init ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "-lhpxd -lhpx_initd ${HPX_PKG_DEBUG_LIBRARIES}")
set(HPX_PKG_LIBRARIES "\${libdir}/libhpx.so \${libdir}/libhpx_init.a ${HPX_PKG_LIBRARIES}")
set(HPX_PKG_DEBUG_LIBRARIES "\${libdir}/libhpxd.so \${libdir}/libhpx_initd.a ${HPX_PKG_DEBUG_LIBRARIES}")
endif()

# Get the include directories we need ...
Expand Down
30 changes: 4 additions & 26 deletions docs/manual/build_system/using_hpx_pkgconfig.qbk
Expand Up @@ -31,7 +31,8 @@ used while building __hpx__):
``
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HPX_LOCATION/lib/pkgconfig
c++ -o hello_world hello_world.cpp \
`pkg-config --cflags --libs hpx_application` -lhpx_iostreams -DHPX_APPLICATION_NAME=hello_world
`pkg-config --cflags --libs hpx_application` \
-lhpx_iostreams -DHPX_APPLICATION_NAME=hello_world
``

[important When using pkg-config with __hpx__, the pkg-config flags must go after
Expand Down Expand Up @@ -100,7 +101,7 @@ build the component library. (where [^$HPX_LOCATION] is the build directory or
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HPX_LOCATION/lib/pkgconfig
c++ -o libhpx_hello_world.so hello_world_component.cpp \
`pkg-config --cflags --libs hpx_component` \
-DHPX_COMPONENT_NAME=hpx_hello_world
-lhpx_iostreams -DHPX_COMPONENT_NAME=hpx_hello_world
``

Now pick a directory in which to install your __hpx__ component libraries. For
Expand All @@ -123,42 +124,19 @@ this example, we'll choose a directory named ''my_hpx_libs''.
linker. You need to add the path $HPX_LOCATION/lib to your linker search
path (for example LD_LIBRARY_PATH on Linux)]

In the ~/my_hpx_libs directory you need to create an ini file inside that
directory which matches the name of the component (as supplied by
`-DHPX_COMPONENT_NAME` above).

[*hello_world.ini]
``
[hpx.components.hello_world]
name = hello_world
path = ${HOME}/my_hpx_libs
``

[note For additional details about ini file configuration and __hpx__, see
[link hpx.manual.init.configuration.loading_ini_files Loading INI Files]]

In addition, you'll need this in your home directory:

[*.hpx.ini]
``
[hpx]
ini_path = $[hpx.ini_path]:${HOME}/my_hpx_libs
``

Now, to build the application that uses this component (hello_world_client.cpp),
we do:

``
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HPX_LOCATION/lib/pkgconfig
c++ -o hello_world_client hello_world_client.cpp \
`pkg-config --cflags --libs hpx_application` \
-lhpx_iostreams -L${HOME}/my_hpx_libs -lhello_world
-L${HOME}/my_hpx_libs -lhello_world -lhpx_iostreams
``

[important When using pkg-config with __hpx__, the pkg-config flags must go after
the [^-o] flag.]


Finally, you'll need to set your LD_LIBRARY_PATH before you can run the program.
To run the program, type:

Expand Down
26 changes: 5 additions & 21 deletions examples/hello_world_component/hello.sh
@@ -1,4 +1,5 @@
#!/bin/bash
#
# Copyright (c) 2012 Steven R. Brandt
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -8,35 +9,18 @@
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$HPX_LOCATION/lib/pkgconfig

# Compile the library
c++ -o libhello_world.so hello_world_component.cpp `pkg-config --cflags --libs hpx_component` -DHPX_COMPONENT_NAME=hello_world
c++ -o libhpx_hello_world.so hello_world_component.cpp `pkg-config --cflags --libs hpx_component` -DHPX_COMPONENT_NAME=hello_world -lhpx_iostreams

# Create the directory where we want to install the library
mkdir -p ~/my_hpx_libs
mv libhello_world.so ~/my_hpx_libs

# If we don't have a .hpx.ini yet, create one and tell it about
# our private hpx library directory
if [ ! -r ~/.hpx.ini ]
then
cat > ~/.hpx.ini <<EOF
[hpx]
ini_path = \$[hpx.ini_path]:${HOME}/my_hpx_libs
EOF
fi

# Create the ini file
cat > ~/my_hpx_libs/hello_world.ini <<EOF
[hpx.components.hello_world]
name = hello_world
path = ${HOME}/my_hpx_libs
EOF
mv libhpx_hello_world.so ~/my_hpx_libs

# Compile the client
c++ -o hello_world_client hello_world_client.cpp `pkg-config --cflags --libs hpx_application` -lhpx_iostreams -lhello_world -L ~/my_hpx_libs
c++ -o hello_world_client hello_world_client.cpp `pkg-config --cflags --libs hpx_application` -L ~/my_hpx_libs -lhpx_hello_world -lhpx_iostreams

# Prepare the environment so that we can run the command
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/my_hpx_libs"

# Run the client, first add our directory to the LD_LIBRARY_PATH
./hello_world_client
./hello_world_client

10 changes: 3 additions & 7 deletions examples/hello_world_component/hello_world_client.cpp
Expand Up @@ -12,9 +12,9 @@ int hpx_main(boost::program_options::variables_map&)
{
// Create a single instance of the component on this locality.
examples::hello_world client =
examples::hello_world::create(hpx::find_here());
hpx::new_<examples::hello_world>(hpx::find_here());

// Invoke the components action, which will print "Hello World!".
// Invoke the component's action, which will print "Hello World!".
client.invoke();
}

Expand All @@ -23,11 +23,7 @@ int hpx_main(boost::program_options::variables_map&)

int main(int argc, char* argv[])
{
// Configure application-specific options.
boost::program_options::options_description desc_commandline(
"usage: " HPX_APPLICATION_STRING " [options]");

return hpx::init(desc_commandline, argc, argv); // Initialize and run HPX.
return hpx::init(argc, argv); // Initialize and run HPX.
}
//]

12 changes: 6 additions & 6 deletions examples/hello_world_component/hello_world_component.cpp
Expand Up @@ -7,14 +7,14 @@
#include "hello_world_component.hpp"
#include <hpx/include/iostreams.hpp>

namespace examples { namespace server
{
#include <iostream>

void hello_world::invoke()
namespace examples { namespace server
{
hpx::cout << "Hello HPX World!\n" << hpx::flush;
}

void hello_world::invoke()
{
hpx::cout << "Hello HPX World!" << std::endl;
}
}}

HPX_REGISTER_COMPONENT_MODULE();
Expand Down
60 changes: 23 additions & 37 deletions examples/hello_world_component/hello_world_component.hpp
Expand Up @@ -15,50 +15,36 @@

namespace examples { namespace server
{

struct HPX_COMPONENT_EXPORT hello_world
: hpx::components::component_base<hello_world>
{
void invoke();
HPX_DEFINE_COMPONENT_ACTION(hello_world, invoke);
};

}

namespace stubs
{

struct hello_world : hpx::components::stub_base<server::hello_world>
{
static void invoke(hpx::naming::id_type const& gid)
struct HPX_COMPONENT_EXPORT hello_world
: hpx::components::component_base<hello_world>
{
hpx::async<server::hello_world::invoke_action>(gid).get();
}
};
void invoke();
HPX_DEFINE_COMPONENT_ACTION(hello_world, invoke);
};
}}

}
HPX_REGISTER_ACTION_DECLARATION(
examples::server::hello_world::invoke_action, hello_world_invoke_action);

struct hello_world
: hpx::components::client_base<hello_world, stubs::hello_world>
namespace examples
{
typedef hpx::components::client_base<hello_world, stubs::hello_world>
base_type;

hello_world(hpx::future<id_type> gid)
: base_type(std::move(gid))
{}

void invoke()
struct hello_world
: hpx::components::client_base<hello_world, server::hello_world>
{
this->base_type::invoke(this->get_id());
}
};

typedef hpx::components::client_base<hello_world, server::hello_world>
base_type;

hello_world(hpx::future<hpx::id_type> f)
: base_type(std::move(f))
{}

void invoke()
{
hpx::async<server::hello_world::invoke_action>(this->get_id()).get();
}
};
}

HPX_REGISTER_ACTION_DECLARATION(
examples::server::hello_world::invoke_action, hello_world_invoke_action);

#endif // HELLO_WORLD_COMPONENT_HPP
//]

0 comments on commit 04fa126

Please sign in to comment.