jeudi 13 août 2015

Precompile C++ vendor Libraries (#include api.h)

First of all, I have to say, that I am an absolute beginner in c++ and all the compiler stuff that is going on for native development.

What I am actually trying to do, is to create a NodeJS binding, to wrap an existing library. The library itself has a api.h which I can include in my wrapper an use it to built my Wrapper methods. The problem which I have, is that the library itself is quite large:

  src/  
    vendor/
      libA/..
      libB/..
      libC/..
      api.h 
      api.cpp 
    addon.cpp (where I am including the "vendor/api.h")

so every time I am compiling my addon.cpp all the libraries have to be recompiled again and again, which sucks. So what is the best way to compile the api once and use it in my addon.cpp (I am not using any of the libs in my addon only the api.h!)

By the way I am working on a Ubuntu 14.04 and I am using Cmake to perform the compilation:

To compile my addon with all the libraries, I am defining all the SOURCE_FILES like this:

file(GLOB SOURCE_FILES
 "src/addon.cpp"
 "src/vendor/*.cpp" "src/vendor/*.h"
 "src/vendor/libA/*.c" "src/vendor/libA/*.h"
 "src/vendor/libB/*.cpp" "src/vendor/libB/*.h"
 "src/vendor/libC/*.c" "src/vendor/libC/*.h"
)

...
add_library(addon SHARED ${SOURCE_FILES})

To compile it, I am calling

cmake-js rebuild

cmake-js because it also loads some NodeJS required stuff, but the CMakeLists.txt file uses the normal cmake syntax

So any help would be really awesome, thanks!



via Chebli Mohamed

Installation of PyICU on Heroku

Anyone know how to install PyICU on Heroku?

Here is what I tried so far:

  1. Created a heroku-buildpack-multi application.

In .buildpacks

http://ift.tt/11oNluO
http://ift.tt/1pcK0Du

In Aptfile

libicu52
libicu-dev

Then heroku run bash

CPATH=$CPATH/app/.apt/usr/include/x86_64-linux-gnu
pip install PyICU

And it installs fine.

I need one way to do that during the application's upload phase (push).

I tried:

pip install --global-option=build_ext --global-option="-I/app/.apt/usr/lib/x86_64-linux-gnu" PyICU

and to create a .pydistutils.cfg file in my home directory as

[build_ext]
include_dirs=/app/.apt/usr/include/x86_64-linux-gnu

In both cases GCC fails to find the header files, but I can see the

-I/app/.apt/usr/lib/x86_64-linux-gnu

flag on the command line.

Used

`gcc -print-prog-name=cc1plus` -v

to find the differences in search paths before and after CPATH=$CPATH/app/.apt/usr/include/x86_64-linux-gnu

Before:

#include <...> search starts here:
/app/.apt/usr/include
.
/usr/include/c++/4.8
/usr/include/x86_64-linux-gnu/c++/4.8
/usr/include/c++/4.8/backward
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include
End of search list.

After:

#include <...> search starts here:
/app/.apt/usr/include
/app/.apt/usr/include/x86_64-linux-gnu
/usr/include/c++/4.8
/usr/include/x86_64-linux-gnu/c++/4.8
/usr/include/c++/4.8/backward
/usr/lib/gcc/x86_64-linux-gnu/4.8/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include
End of search list.

But I'm not a C++ programmer and cannot find what is wrong. Any ideas?



via Chebli Mohamed

Can I convert bool in model to yes/no in a QComboBox

I have a database with a column value 0/1.

I use QSqlRelationalTableModel for showing data to widget.

Is it possible to show Yes for 1 and No for 0 in a QComoboBox? And also, when I select yes/no, it should save to DB as 1/0.

Can I do something with setData() and getData() functions? Could someone give a clue how to start?

UPDATE:

    mpCountryModel->setTable("CountryMaster");
    mpCountryModel->select();

    ui->comboBox->setModel(mpCountryModel);
    ui->comboBox->setModelColumn(5);

As in column 5 has value 0 or 1, the same will display 0 and 1, right?



via Chebli Mohamed

Using Qt’s signals and slots when the same signal can come from multiple places

Qt’s signal and slot mechanism works fine when you have events that occur in one component and need to be handled by one or more other components.

My situation is that an event can occur in either of two classes and it needs to be handled by each of those classes (as well as by a couple of others). For example, suppose that I’m writing a modal text editor. The mode can be changed by the user (by pressing a button on a toolbar) or by the application (when a new file is opened). I might have

// Toolbar.h

signals:
    void user_changed_mode(EditingMode new_mode);
    // connected to AppController::user_changed_mode

public slots:
    void mode_changed(EditingMode new_mode);

// AppController.h

signals:
    void mode_changed(EditingMode new_mode);
    // connected to Toolbar::mode_changed

public slots:
    void user_changed_mode(EditingMode new_mode);

It just seems awkward to me to have two signals that convey the same information but which have different names (and likewise for the slots). Is there a simple way to use the signals and slots mechanism when the same event can originate from multiple places?



via Chebli Mohamed

Calling a function with a same name as a parent class function pointer

I'm trying to get a variety of Nodes to run a defined execute function that is passed in to a constructor and stored (and called) from a function pointer variable.

class Node{
    std::string(*execute)();
};

Node::Node(std::string(*funcPointer)()){
    execute = funcPointer;
}

I also have several derived classes that all also have an execute funcion

class redNode : public Node{
    std::string execute();
};

std::string redNode::execute(){
    return "I'm red";
}

class blueNode : public Node{
    std::string execute();
};

std::string blueNode::execute(){
    return "I'm red";
}

Then, I want to call all of the Node's execute functions.

std::string myFunc(){
     return "my Func";
}

Node mynode = new Node(&myFunc);
//other instantiations here...

myRedNode.execute();
myBlueNode.execute();
myNode.execute();

However, trying to call .execute() of myRedNode or myBlueNode doesn't work because the execute variable that's a part of the parent class was never set and it seems to be calling that. Trying to then set the execute variable

myBlueNode.execute = &BlueNode::execute;

gives a error C2659: '=' function as left operand, even when I rename the function I'm setting the variable to.

How do I solve this problem? How do correctly call function with a same name as a parent class function pointer?



via Chebli Mohamed

GCC/G++ Dockerfile builds locally; fails in Hub

I recently submitted this Dockerfile to the Hub

FROM ubuntu:14.04
MAINTAINER Jeyan Oorjitham <jeyoor@gmx.com>
RUN apt-get update && apt-get install -y \
   build-essential \
   cmake \
   git \
   libncurses-dev
RUN git clone http://ift.tt/1MqWxol
RUN ["/bin/bash", "-c",  "cd avida; ./build_avida"]
CMD ["/bin/bash"]

It is intended to build Avida from source.

The build succeeds locally, but when I receive the following error from the Docker Hub.

[91mc++: internal compiler error: Killed (program cc1plus)
[0m
[91mPlease submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.8/README.Bugs> for instructions.
...
Linking CXX executable ../../../bin/apto-test
...
Built target apto-test
[91mmake[1]: *** [avida-core/CMakeFiles/avida-core.dir/all] Error 2
[0m
[91mmake: [0m
[91m*** [all] Error 2

Full output

The build seems to be failing around the time it tries to link together the test executable for Apto.

Some Googling led me to this thread which seems to point to a lack of memory when linking large binaries...

Could memory be the problem or am I missing something else? Is there any way for me to increase the memory allocated to the Docker Hub build?



via Chebli Mohamed

Is there any performance difference between accessing a hardcode array and a run time initialization array?

For example, I want to create a square root table using array SQRT[i] to optimize a game, but I don't know if there is performance difference between the following initialization when accessing the value of SQRT[i]:

  1. Hardcode array

    int SQRT[]={0,1,1,1,2,2,2,2,2,3,3,.......255,255,255}
    
    
  2. Generate value at run time

    int SQRT[65536];
    int main(){
        for(int i=0;i<65536;i++){
            SQRT[i]=sqrt(i);
        }
        //other code
        return 0;
    }
    
    

Some example of accessing them:

    if(SQRT[a*a+b*b]>something)
    ...

At start, I thought they should be the same, but I don't know if the program stores or access a hard-code array in different way. Also, I don't know if compiler will optimize the hard-code array to speed up the access time, is there performance difference between them when accessing the array?



via Chebli Mohamed