问:
How to substring one by one in one button in php?
How to substring one by one in one button in php ?
Example:
$myvar="abc";
i need one button when click 1 time=display a, click 2time display b, and click 3time
display c. click how many time ?depend on string of $myvar.

Best regards

答:
sure you should look into javascript for that, sir.

anyway, i'll give you some codes, assuming the button has an id as "Btn";

```<code>var str = 'abc';
var n = 0;
var btn = document.getElementById('Btn');

btn.onclick = function() {
    alert(str.substring(n, n + 1));
    n = (n + 1) % 3；
};
</code>```

Body:
sure you should look into javascript for that, sir.

anyway, i'll give you some codes, assuming the button has an id as "Btn";

var str = 'abc';
var n = 0;
var btn = document.getElementById('Btn');

btn.onclick = function() {
    alert(str.substring(n, n + 1));
    n = (n + 1) % 3；
};


来源: stackexchange

问:
How to run multiple instance of WinForms application
I have developed a WinForms application for two purposes

1) It has a form which will accept configuration from user and store it

2) Based on configuration values entered in step 1. a task scheduler will be created that will transfer files from local folder to FTP

Now, when task is running from scheduler and at the same time if i open a form it will give me error like

```<code>Process/exe is already in use. Cannot start new instance.
</code>```

Is it possible to open form in different instance to that of scheduler task?

```<code>[STAThread]
static void Main(string[] args)
{

if (args.Length > 0 && args[0] == "AutoRun")
{
Logger.Info("Auto run successfull.");
GetConfigValues getConfigValues = new GetConfigValues();
UploadToFTP uploadToFTP = new UploadToFTP();
string result = uploadToFTP.UploadFile(getConfigValues.LocalPath, getConfigValues.FTPServer, getConfigValues.FTPFolderPath, getConfigValues.FTPUsername, getConfigValues.FTPPassword);
}
else
{
Logger.Info("Manual run successfull.");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
    }
}
</code>```

答:
Assuming this is related to Task Scheduler and not your application specifically:

You can configure the behaviour of the Task Scheduler task when the target process is already running. In the UI, this is on the Settings tab, "If the task is already running...". The default is "Do not start a new instance"; what you want is probably "Run a new instance in parallel", though a better option would probably be to have a different executable for handling the background tasks, and queuing the consecutive runs instead.

ContentLicense: CC BY-SA 4.0

Body:
I have developed a WinForms application for two purposes

1) It has a form which will accept configuration from user and store it

2) Based on configuration values entered in step 1. a task scheduler will be created that will transfer files from local folder to FTP

Now, when task is running from scheduler and at the same time if i open a form it will give me error like

Process/exe is already in use. Cannot start new instance.

Is it possible to open form in different instance to that of scheduler task?

[STAThread]
static void Main(string[] args)
{

if (args.Length > 0 && args[0] == "AutoRun")
{
Logger.Info("Auto run successfull.");
GetConfigValues getConfigValues = new GetConfigValues();
UploadToFTP uploadToFTP = new UploadToFTP();
string result = uploadToFTP.UploadFile(getConfigValues.LocalPath, getConfigValues.FTPServer, getConfigValues.FTPFolderPath, getConfigValues.FTPUsername, getConfigValues.FTPPassword);
}
else
{
Logger.Info("Manual run successfull.");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
    }
}


问:
Creating Methods in Java (Beginner)
I am pretty new to Java so I apologize if my question is pretty basic. What I'm struggling with is creating a method. There is already an object called "robot" and a method called turnLeft();. I would like to create a new method called turnRight();. I tried doing this by writing something like:

```<code>public void turnRight(Robot robot) {
      robot.turnLeft();
      robot.turnLeft();
      robot.turnLeft();

   }
</code>```

Something seems to be wrong since I cannot call for that method, what is it that is missing? I'd appreciate any help. Thanks!

/Nick

答:
Because your methods I mean turn.right or also turn.left don't return anything and just turn left you should write the function with void like this</p>

```<code>           public static void turnRight(Robot robot) {
                  robot.turnLeft( );
                  robot.turnLeft( );
                  robot.turnLeft( );
            }
</code>```

Title: Creating Methods in Java (Beginner)

Body:
I am pretty new to Java so I apologize if my question is pretty basic. What I'm struggling with is creating a method. There is already an object called "robot" and a method called turnLeft();. I would like to create a new method called turnRight();. I tried doing this by writing something like:

public void turnRight(Robot robot) {
      robot.turnLeft();
      robot.turnLeft();
      robot.turnLeft();

   }

Something seems to be wrong since I cannot call for that method, what is it that is missing? I'd appreciate any help. Thanks!

/Nick

Body:
Because your methods I mean turn.right or also turn.left don't return anything and just turn left you should write the function with void like this

           public static void turnRight(Robot robot) {
                  robot.turnLeft( );
                  robot.turnLeft( );
                  robot.turnLeft( );
            }


问:
Problem using aspnet_compiler with VS2010 project to build assemblies for .NET 3.5
I'm trying to use aspnet_compile.exe to compile an ASP.NET web application.  The command I'm using looks like this:

```<code>aspnet_compiler.exe -f -c -p PATH_TO_WEB_APP -v /
-fixednames -errorstack PATH_TO_DESIRED_FOLDER
</code>```

This used to be working fine, but I'm trying to migrate the projects involved from VS2008 to VS2010.  But, I don't want to upgrade all of the projects to .NET 4 (yet).  So they are all working in VS2010 against .NET 3.5 and building just fine through there normally.

But, when I issue the aspnet_compiler command (using the 2.0 version of the compiler), I get the following.

```<code>error ASPCONFIG: Could not load file or assembly 'ASSEMBLY_NAME'
or one of its dependencies. This assembly is built by a runtime newer than
the currently loaded runtime and cannot be loaded.
</code>```

But if I try to use the new aspnet_compiler included with VS2010, it builds with .NET 4, and then the created assemblies can't be used by the rest of the 3.5 assemblies.

So my question: how do I use aspnet_compiler against a VS2010 web application project, while still having it built for .NET 2.0/3.5?

答:
%windir%\Microsoft.NET\Framework\v2.0.50727

Look here for more info:

http://msdn.microsoft.com/en-us/library/ms229863.aspx#findingthecorrectversion

ContentLicense: CC BY-SA 2.5

Body:
I'm trying to use aspnet_compile.exe to compile an ASP.NET web application.  The command I'm using looks like this:

aspnet_compiler.exe -f -c -p PATH_TO_WEB_APP -v /
-fixednames -errorstack PATH_TO_DESIRED_FOLDER

This used to be working fine, but I'm trying to migrate the projects involved from VS2008 to VS2010.  But, I don't want to upgrade all of the projects to .NET 4 (yet).  So they are all working in VS2010 against .NET 3.5 and building just fine through there normally.

But, when I issue the aspnet_compiler command (using the 2.0 version of the compiler), I get the following.

error ASPCONFIG: Could not load file or assembly 'ASSEMBLY_NAME'
or one of its dependencies. This assembly is built by a runtime newer than
the currently loaded runtime and cannot be loaded.

But if I try to use the new aspnet_compiler included with VS2010, it builds with .NET 4, and then the created assemblies can't be used by the rest of the 3.5 assemblies.

So my question: how do I use aspnet_compiler against a VS2010 web application project, while still having it built for .NET 2.0/3.5?

ContentLicense: CC BY-SA 3.0


问:
Mock an object in Espresso
Today I started to use Espresso to test an Activity, I am practical with Junit tests but do not understand how to mock, I have the line cashPeriod that obviously gives me a NPE when I try to launch the activity with Espresso

```<code>override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    //no layout preview possible
    setContentView(R.layout.activity_combi_book_balance)
    title = getString(R.string.balance_details)
    setupActionBarWithHomeEnabled(true)

    val cashPeriod: CashPeriod = intent.extras.getParcelable(PERIOD_OBJECT_EXTRA)
    val sections = showList(cashPeriod)
    setAdapter(sections)
}
</code>```

and my Espresso test is

```<code>@Test
    fun appLaunchesSuccessfully() {
        ActivityScenario.launch(CombiBookBalanceDetailActivity::class.java)
    }
</code>```

Now if I stub the cashPeriod in the onCreate giving some hardcoded values, the test passes, but I need to do that in the test class of course

How can I mock the line val cashPeriod: CashPeriod = intent.extras.getParcelable(PERIOD_OBJECT_EXTRA) in my espresso test? Is different by Junit, where I use Mockito/mockito-kotlin/mockk and give a behaviour with when /// return //that

答:
You have to use ActivityTestRule
See this

Title: Mock an object in Espresso

Body:
Today I started to use Espresso to test an Activity, I am practical with Junit tests but do not understand how to mock, I have the line cashPeriod that obviously gives me a NPE when I try to launch the activity with Espresso

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    //no layout preview possible
    setContentView(R.layout.activity_combi_book_balance)
    title = getString(R.string.balance_details)
    setupActionBarWithHomeEnabled(true)

    val cashPeriod: CashPeriod = intent.extras.getParcelable(PERIOD_OBJECT_EXTRA)
    val sections = showList(cashPeriod)
    setAdapter(sections)
}

and my Espresso test is

@Test
    fun appLaunchesSuccessfully() {
        ActivityScenario.launch(CombiBookBalanceDetailActivity::class.java)
    }

Now if I stub the cashPeriod in the onCreate giving some hardcoded values, the test passes, but I need to do that in the test class of course

How can I mock the line val cashPeriod: CashPeriod = intent.extras.getParcelable(PERIOD_OBJECT_EXTRA) in my espresso test? Is different by Junit, where I use Mockito/mockito-kotlin/mockk and give a behaviour with when /// return //that


问:
VueJS v-if = array[index] is not working
I wanted to make a component which gets text-box when mouse is over the image.

Below is HTML template.

```<code><section class="item-container" v-for="(item, index) in items">
  <div class="image-box" @mouseenter="changeStatus(index)">
    <img class="image" src="item.link" alt>
  </div>
  <div class="text-box" @mouseleave="changeStatus(index)" v-if="show[index]">
    <h4>{{ item.name }}</h4>
    <p>{{ item.content }}</p>
  </div>
</section>
</code>```

And below is app.js

```<code>new Vue({
  el: '#app',
  data: {
    show: [false, false, false],
    items: [
      {
        name: 'Author 1',
        content: 'Content 1'
      },
      {
        name: 'Author 2',
        content: 'Content 2'
      },
      {
        name: 'Author 3',
        content: 'Content 3'
      }
    ]
  },
  methods: {
    changeStatus: function(index) {
      this.show[index] = !this.show[index];
      console.log(this.show);
      console.log(this.show[index]);  // console gets it as expected
    }
  }
});
</code>```

When I execute above codes, I can find that the show property has changed. However, v-if is not updated. Can't we use array[index] for v-if or is there other reason for it?

答:
In component in methods you can use:</p>

```<code>this.$set(this.show, index, !this.show[index])
</code>```

Body:
I wanted to make a component which gets text-box when mouse is over the image.

Below is HTML template.

{{ item.name }}

{{ item.content }}

And below is app.js

new Vue({
  el: '#app',
  data: {
    show: [false, false, false],
    items: [
      {
        name: 'Author 1',
        content: 'Content 1'
      },
      {
        name: 'Author 2',
        content: 'Content 2'
      },
      {
        name: 'Author 3',
        content: 'Content 3'
      }
    ]
  },
  methods: {
    changeStatus: function(index) {
      this.show[index] = !this.show[index];
      console.log(this.show);
      console.log(this.show[index]);  // console gets it as expected
    }
  }
});

When I execute above codes, I can find that the show property has changed. However, v-if is not updated. Can't we use array[index] for v-if or is there other reason for it?

Body:
In component in methods you can use:

this.$set(this.show, index, !this.show[index])


问:
CI: Why do all my jqxhr requests fail when $config['csrf_protection'] = TRUE?
In going through my CI 3.1.11 code to clean it up (hosted by XAMPP v2.3.4 localhost) it seems I have done something to prevent the server from accepting any jqxhr requests if I have CI's Cross-Site Request Forgery (csrf) protection running.

I am using other http requsts to get information from the server and external files such as lines in the  that load jquery, my css file, etc. These work fine no matter the state of the csrf setting.

When I have set:
    $config['csrf_protection'] = TRUE; My jqxhr requests always get the http 403 error (rejected request that implies a suspected hacking attempt). My basic question is to understand why this happens so I can correct it and run the csrf protection.

I don't know if this is related but I found that I only need to provide the controller and function to the jqxhr rather than the complete url. Most examples I've seen online provide embedded Php code to insert the base_url in front. Something in the system (CI?) seems to want to prepend the base_url  to the controller/function no matter what. If I insert it myself, it creates an unusable url with the base_url appearing twice.

If I use . . .
    var url= "C_library/updateTitle";
     $.post(url, { 'tID':tID, 'newTitle':newTitle }, function(data) { . .

. . . the request works if csrf is not running. If csrf protection is running, this would be a typical console error report:

```<code>XHRPOSThttp://localhost/MZlocal/C_library/updateTitle [HTTP/1.1 403 Forbidden 32ms]
</code>```

Note that the url is correctly formed.

Also, probably not relevant but here's my .htaccess file - which works (eliminates "index.php" from the address bar).

```<code>RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</code>```

csrf protection is an important feature of CI that I'd really like to understand better. Any help or hints as to where I should look is appreciated.

Full csrf config.php:

```<code>$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
</code>```

答:
The whole idea of csrf-protection is having a token generated by your CI framework and beeing send to the server with every form submission or ajax request to get sure the request was made via your website. You have to send the token along with your request no matter if you submit a normal form or if you do an ajax request. If you do an ajax request there are 2 steps to make.

1) Make sure the token is provided in your sourcecode by either using the CodeIgniter form-helper (which is generating the token for you automatically) or by implementing a hidden input field (like @Boominathan Elango already posted)

<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />

You could provide the token value in many different ways but this one is fine in your case I guess.

2) Then you have to send the token along with your ajax request:

In your Javascript code:

```<code>// first get the token value from your hidden input field:
var csrfTokenValue = $('input[name=csrf_test_name]').val();

// You Ajax url - check if this here is the right one for you
var ajaxUrl = 'http://localhost/MZlocal/C_library/updateTitle';

$.ajax({
  type: "POST",
  url: ajaxUrl,
  data: {
    'csrf_test_name' : csrfTokenValue,
    'tID': tID,
    'newTitle':newTitle
  },
  success: success,
  dataType: dataType
});
</code>```

Assuming you have the config still like posted > csrf_test_name as token name.
Maybe you have to alter your javascript a little bit (according to the data you want to send with your ajax request) but but in general it should work like that. Catching errors and so on..

Body:
In going through my CI 3.1.11 code to clean it up (hosted by XAMPP v2.3.4 localhost) it seems I have done something to prevent the server from accepting any jqxhr requests if I have CI's Cross-Site Request Forgery (csrf) protection running.

I am using other http requsts to get information from the server and external files such as lines in the  that load jquery, my css file, etc. These work fine no matter the state of the csrf setting.

When I have set:
    $config['csrf_protection'] = TRUE; My jqxhr requests always get the http 403 error (rejected request that implies a suspected hacking attempt). My basic question is to understand why this happens so I can correct it and run the csrf protection.

I don't know if this is related but I found that I only need to provide the controller and function to the jqxhr rather than the complete url. Most examples I've seen online provide embedded Php code to insert the base_url in front. Something in the system (CI?) seems to want to prepend the base_url  to the controller/function no matter what. If I insert it myself, it creates an unusable url with the base_url appearing twice.

If I use . . .
    var url= "C_library/updateTitle";
     $.post(url, { 'tID':tID, 'newTitle':newTitle }, function(data) { . .

. . . the request works if csrf is not running. If csrf protection is running, this would be a typical console error report:

XHRPOSThttp://localhost/MZlocal/C_library/updateTitle [HTTP/1.1 403 Forbidden 32ms]

Note that the url is correctly formed.

Also, probably not relevant but here's my .htaccess file - which works (eliminates "index.php" from the address bar).

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

csrf protection is an important feature of CI that I'd really like to understand better. Any help or hints as to where I should look is appreciated.

Full csrf config.php:

$config['csrf_protection'] = TRUE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();

Body:
The whole idea of csrf-protection is having a token generated by your CI framework and beeing send to the server with every form submission or ajax request to get sure the request was made via your website. You have to send the token along with your request no matter if you submit a normal form or if you do an ajax request. If you do an ajax request there are 2 steps to make.

1) Make sure the token is provided in your sourcecode by either using the CodeIgniter form-helper (which is generating the token for you automatically) or by implementing a hidden input field (like @Boominathan Elango already posted)

<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />

You could provide the token value in many different ways but this one is fine in your case I guess.

2) Then you have to send the token along with your ajax request:

In your Javascript code:

// first get the token value from your hidden input field:
var csrfTokenValue = $('input[name=csrf_test_name]').val();

// You Ajax url - check if this here is the right one for you
var ajaxUrl = 'http://localhost/MZlocal/C_library/updateTitle';

$.ajax({
  type: "POST",
  url: ajaxUrl,
  data: {
    'csrf_test_name' : csrfTokenValue,
    'tID': tID,
    'newTitle':newTitle
  },
  success: success,
  dataType: dataType
});

Assuming you have the config still like posted > csrf_test_name as token name.
Maybe you have to alter your javascript a little bit (according to the data you want to send with your ajax request) but but in general it should work like that. Catching errors and so on..


问:
Why does SSD resize random crops during data augmentation?
The SSD paper details its random-crop data augmentation scheme as:

Data augmentation To make the model more robust to various input object sizes and
  shapes, each training image is randomly sampled by one of the following options:
  – Use the entire original input image.
  – Sample a patch so that the minimum jaccard overlap with the objects is 0.1, 0.3,
  0.5, 0.7, or 0.9.
  – Randomly sample a patch.
  The size of each sampled patch is [0.1, 1] of the original image size, and the aspect ratio
  is between 1 and 2. We keep the overlapped part of the ground truth box if the center of
  it is in the sampled patch. After the aforementioned sampling step, each sampled patch
  is resized to fixed size and is horizontally flipped with probability of 0.5, in addition to
  applying some photo-metric distortions similar to those described in [14].
  https://arxiv.org/pdf/1512.02325.pdf

My question is: what is the reasoning for resizing crops that range in aspect ratios between 0.5 and 2.0?

For instance if your input image is 300x300, reshaping a crop with AR=2.0 back to square resolution will severely stretch objects (square features become rectangular, circles become ellipses, etc.) I understand small distortions may be good to improve generalization, but training the network on objects distorted up to 2x in either dimension seems counter-productive. Am I misunderstanding how random-crop works?

[Edit] I completely understand that augmented images need to be the same size as the original -- I'm more wondering why the authors don't fix the Aspect Ratio to 1.0 to preserve object proportions.

答:
Personally I consider that any transformation makes sense as long as you as a human can still identify the object/subject, and as long as they make sense in the receptive field of the network. Also I guess somehow that the aspect ratio might help to learn some kind of perspective distortion (look at the cow in fig 5, it's kind of "compressed"). Objects like a cup, a tree, a chair, even stretched are still identifiable. Otherwise you could also consider that some point-controlled or skew transforms just don't make sense as well.

Then, if you are working with different images than natural images, without perspective, it is probably not a good idea to do so. If your image shows objects of a fixed known size like in a microscope or other medical imaging device, and if your object has more or less a fixed size (let's say a cell), then it's probably not a good idea to perform strong distortion on the scale (like a cell twice as large), maybe then a cell twice as an ellipse actually makes more sense.

With this library, you can perform strong augmentations, but not all of them make sense if you look at the image here:


问:
Switch Style Radio Button Using JavaScript
I would like to know how I can make a switch style function to change the website style between 2 styles. Here's what I have done so far. Please check. Thank you.

```<code>function switchcss() {
    document.write('<link rel="stylesheet" type"text/css" href="css/style1.css">');
    document.write('<link rel="stylesheet" type"text/css" href="css/style2.css">');
}
</code>```

http://jsfiddle.net/APbSm/

答:
There are many ways to skin a cat, here is one approach, using jQuery:

```<code><!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Switch Style Radio Button Using JavaScript</title>

    <link rel="stylesheet" href="css/style1.css" media="all" />
</head>

<body>

<input type="radio" name="switch" id="style1" value="Theme 1" checked="checked" />Theme 1<br />
<input type="radio" name="switch" id="style2" value="Theme 2" />Theme 2

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
    $('#style1').click(function() {
        $('link[rel="stylesheet"]').attr({
            href: 'css/style1.css'
        });
    });

    $('#style2').click(function() {
        $('link[rel="stylesheet"]').attr({
            href: 'css/style2.css'
        });
    });
</script>

</body>
</html>
</code>```

I realize this is not the best approach, but answers the original poster's question with as little code as possible — kudos that it can essentially be copied, pasted, and implemented with ease.

However, a greater understanding of the problem can yield a much better solution.

Body:
I would like to know how I can make a switch style function to change the website style between 2 styles. Here's what I have done so far. Please check. Thank you.

function switchcss() {
    document.write('<link rel="stylesheet" type"text/css" href="css/style1.css">');
    document.write('<link rel="stylesheet" type"text/css" href="css/style2.css">');
}

http://jsfiddle.net/APbSm/

Body:
There are many ways to skin a cat, here is one approach, using jQuery:

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>Switch Style Radio Button Using JavaScript</title>

    <link rel="stylesheet" href="css/style1.css" media="all" />
</head>

<body>

<input type="radio" name="switch" id="style1" value="Theme 1" checked="checked" />Theme 1<br />
<input type="radio" name="switch" id="style2" value="Theme 2" />Theme 2

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
    $('#style1').click(function() {
        $('link[rel="stylesheet"]').attr({
            href: 'css/style1.css'
        });
    });

    $('#style2').click(function() {
        $('link[rel="stylesheet"]').attr({
            href: 'css/style2.css'
        });
    });
</script>

</body>
</html>

I realize this is not the best approach, but answers the original poster's question with as little code as possible — kudos that it can essentially be copied, pasted, and implemented with ease.

However, a greater understanding of the problem can yield a much better solution.


问:
Angular universal window is not defined
im trying to run SSR on my angular8 project but when i run server.js this error happens

    home/daba/client/dist/server/main.js:288235
})(window, document, 'Hammer');
^

ReferenceError: window is not defined
at Object.yLV6 (/home/daba/client/dist/server/main.js:288235:4)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.ZAI4 (/home/daba/client/dist/server/main.js:171354:1)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.V7fC (/home/daba/client/dist/server/main.js:161821:10)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.K011 (/home/daba/client/dist/server/main.js:125145:37)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.0 (/home/daba/client/dist/server/main.js:1251:18)
at webpack_require (/home/daba/
client/dist/server/main.js:20:30)
`
```

i've tried many things but still nothing

答:
Have you tried to add this code to your server.ts before const app = express();? It may help to avoid exceptions from thirty party libraries which don't allow using them on server-side.

```<code>import * as fs from 'fs';
import * as domino from 'domino';

const template = fs.readFileSync('browser/index.html').toString();
const win = domino.createWindow(template);

global['window'] = win;
global['document'] = win.document;
global['navigator'] = win.navigator;
global['Event'] = null;
</code>```

Title: Angular universal window is not defined

Body:
im trying to run SSR on my angular8 project but when i run server.js this error happens

    home/daba/client/dist/server/main.js:288235
})(window, document, 'Hammer');
^

ReferenceError: window is not defined
at Object.yLV6 (/home/daba/client/dist/server/main.js:288235:4)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.ZAI4 (/home/daba/client/dist/server/main.js:171354:1)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.V7fC (/home/daba/client/dist/server/main.js:161821:10)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.K011 (/home/daba/client/dist/server/main.js:125145:37)
at webpack_require (/home/daba/client/dist/server/main.js:20:30)
at Object.0 (/home/daba/client/dist/server/main.js:1251:18)
at webpack_require (/home/daba/
client/dist/server/main.js:20:30)
`

i've tried many things but still nothing

Body:
Have you tried to add this code to your server.ts before const app = express();? It may help to avoid exceptions from thirty party libraries which don't allow using them on server-side.

import * as fs from 'fs';
import * as domino from 'domino';

const template = fs.readFileSync('browser/index.html').toString();
const win = domino.createWindow(template);

global['window'] = win;
global['document'] = win.document;
global['navigator'] = win.navigator;
global['Event'] = null;


问:
C# LINQ Zipping 2 list of lists based on uniqueness of objects
I am trying to zip 2 lists of lists of objects - only where the resulting zipped list would contain lists of distinct objects (list 2's lists sometimes have duplicate objects when compared to list 1). The count of objects in the resultant list must be maintained, meaning we can't have lists of differing sizes. The number of lists in list 1 is greater the number in list 2. Which would mean repeatedly going through list 2 when zipping.

The above is represented using loops below. Is this possible using only linq?

```<code>//this list of list contains the larger number of elements to which the 2nd list of list needs to be joined
List<List<object>> FullList = new List<List<object>>(); //is not empty - instantiated with some list

//2nd list of list - contains duplicates of the 1st list in terms of the objects in the underlying list
List<List<object>> comboBaseList = new List<List<object>>(); //is not empty - instantiated with some list
List<List<object>> comboList = comboBaseList;

//need to zip lists where there are no duplicate objects in the 2nd list's list, the count of the 1st list of list remains the same as FullList
List<List<object>> finalList = new List<List<object>>(); //empty - meant to hold final combined list

int i = 0;

foreach iList in FullList
{
    if (i < comboList.count)
    {
        while (iList.Select(x => x.Id).Contains(comboList[i].Select(y => y.Id)))
        {
            i += 1;
        }
        finalList.Add(iList.Zip(comboList[i], (x, y) => x.Union(y))); //**CAN WE BYPASS THE LOOPS AND JUST USE LINQ?
        comboList.RemoveAt(i);
        i = 0;
    }
    else
    {
        comboList = comboBaseList;
        i = 0;
    }
}
</code>```

To simplify the data I'll use lists of lists of integers - which could be the Id's of the objects in my case

```<code>FullList =
(
{1,2,3},
{2,5,6},
{7,8,9}
)

comboList =
(
{2,5},
{8,9}
)
</code>```

I want to zip the above lists to yield the resultant as below - Note that there are 3 results as per FullList and the undelying lists have distinct integers

```<code>finalList =
{
 {1,2,3,8,9},
 {2,5,6,8,9},
 {7,8,9,2,5}
}
</code>```

答:
```<code>var fullList = new List<List<int>>()
        {
            new List<int>() {1,2,3},
            new List<int>() {2,5,6},
            new List<int>() {7,8,9}
        };

 var comboList = new List<List<int>>()
        {
            new List<int>() {2,5},
            new List<int>() {8,9},
        };

fullList.ForEach(i =>
        {
            comboList.ForEach(j =>
            {
                if (i.All(x => !j.Contains(x)))
                {
                    i.AddRange(j);
                    return;
                };
            });
        });
</code>```

Body:
I am trying to zip 2 lists of lists of objects - only where the resulting zipped list would contain lists of distinct objects (list 2's lists sometimes have duplicate objects when compared to list 1). The count of objects in the resultant list must be maintained, meaning we can't have lists of differing sizes. The number of lists in list 1 is greater the number in list 2. Which would mean repeatedly going through list 2 when zipping.

The above is represented using loops below. Is this possible using only linq?

//this list of list contains the larger number of elements to which the 2nd list of list needs to be joined
List<List<object>> FullList = new List<List<object>>(); //is not empty - instantiated with some list

//2nd list of list - contains duplicates of the 1st list in terms of the objects in the underlying list
List<List<object>> comboBaseList = new List<List<object>>(); //is not empty - instantiated with some list
List<List<object>> comboList = comboBaseList;

//need to zip lists where there are no duplicate objects in the 2nd list's list, the count of the 1st list of list remains the same as FullList
List<List<object>> finalList = new List<List<object>>(); //empty - meant to hold final combined list

int i = 0;

foreach iList in FullList
{
    if (i < comboList.count)
    {
        while (iList.Select(x => x.Id).Contains(comboList[i].Select(y => y.Id)))
        {
            i += 1;
        }
        finalList.Add(iList.Zip(comboList[i], (x, y) => x.Union(y))); //**CAN WE BYPASS THE LOOPS AND JUST USE LINQ?
        comboList.RemoveAt(i);
        i = 0;
    }
    else
    {
        comboList = comboBaseList;
        i = 0;
    }
}

To simplify the data I'll use lists of lists of integers - which could be the Id's of the objects in my case

FullList =
(
{1,2,3},
{2,5,6},
{7,8,9}
)

comboList =
(
{2,5},
{8,9}
)

I want to zip the above lists to yield the resultant as below - Note that there are 3 results as per FullList and the undelying lists have distinct integers

finalList =
{
 {1,2,3,8,9},
 {2,5,6,8,9},
 {7,8,9,2,5}
}


答:
Okay, it sounds like you might want something like:

var result = fullList
    .Select(original =>
       // We want the original sublist...
       original
           // concatenated with...
           .Concat(
           // ... any comboList element
           comboList
               // which is completely distinct from "original"
               .Where(cl => !original.Intersect(cl).Any())
               // ... flattening all such comboLists
               .SelectMany(cl => cl))
           .ToList())
    .ToList();
```

<p>Here's a complete example:</p>

<pre class="lang-cs prettyprint-override"><code>using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var fullList = new[]
        {
            new[] { 1, 2, 3 },
            new[] { 2, 5, 6 },
            new[] { 7, 8, 9 }
        };

        var comboList = new[]
        {
            new[] { 2, 5 },
            new[] { 8, 9 }
        };

        var result = MergeCombinations(fullList, comboList);
        foreach (var item in result)
        {
            Console.WriteLine(string.Join(", ", item));
        }
    }

    static List<List<T>> MergeCombinations<T>(
        IEnumerable<IEnumerable<T>> fullList,
        IEnumerable<IEnumerable<T>> comboList)
    {
        var result = fullList
            .Select(original =>
                // We want the original sublist...
                original
                    // concatenated with...
                    .Concat(
                    // ... any comboList element
                       comboList
                           // which is completely distinct from "original"
                           .Where(cl => !original.Intersect(cl).Any())
                           // ... flattening all such comboLists
                          .SelectMany(cl => cl))
                   .ToList())
             .ToList();
        return result;
    }
}
</code>```

Title: C# LINQ Zipping 2 list of lists based on uniqueness of objects

Body:
Okay, it sounds like you might want something like:

var result = fullList
    .Select(original =>
       // We want the original sublist...
       original
           // concatenated with...
           .Concat(
           // ... any comboList element
           comboList
               // which is completely distinct from "original"
               .Where(cl => !original.Intersect(cl).Any())
               // ... flattening all such comboLists
               .SelectMany(cl => cl))
           .ToList())
    .ToList();

Here's a complete example:

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        var fullList = new[]
        {
            new[] { 1, 2, 3 },
            new[] { 2, 5, 6 },
            new[] { 7, 8, 9 }
        };

        var comboList = new[]
        {
            new[] { 2, 5 },
            new[] { 8, 9 }
        };

        var result = MergeCombinations(fullList, comboList);
        foreach (var item in result)
        {
            Console.WriteLine(string.Join(", ", item));
        }
    }

    static List<List<T>> MergeCombinations<T>(
        IEnumerable<IEnumerable<T>> fullList,
        IEnumerable<IEnumerable<T>> comboList)
    {
        var result = fullList
            .Select(original =>
                // We want the original sublist...
                original
                    // concatenated with...
                    .Concat(
                    // ... any comboList element
                       comboList
                           // which is completely distinct from "original"
                           .Where(cl => !original.Intersect(cl).Any())
                           // ... flattening all such comboLists
                          .SelectMany(cl => cl))
                   .ToList())
             .ToList();
        return result;
    }
}


问:
jmeter execution comparison with previous build in Jenkins
I am interested to publish jmeter report in Jenkins and set the pipeline as "failed" if there are degradation in terms of performances between the previous executions.

Below the configuration set in my Jenkinsfile for my jmeter results:

```<code>                perfReport filterRegex: '',
                        relativeFailedThresholdNegative: 0,
                        relativeFailedThresholdPositive: 0,
                        relativeUnstableThresholdNegative: 0,
                        relativeUnstableThresholdPositive: 0,
                        sourceDataFiles: 'resultsJmeter/output/*.xml'
                    }
</code>```

Is there any way to evaluate automatically the previous executions (if any) ?

答:
As per Performance Trend Reporting article:

You can configure the error percentage thresholds and the relative percentage thresholds which would make the project unstable or failed or set them to -1 to disable the feature

As per How to Use the Jenkins Performance Plugin

Set the following values:

```<code>Unstable: 10
Failed: 60
</code>```

This configuration will mark the build as unstable when errors are at 10% and as failed when 60% of our requests failed.

The relevant pipeline syntax would be:

```<code>perfReport errorFailedThreshold: 60, errorUnstableThreshold: 10, filterRegex: '', sourceDataFiles: 'resultsJmeter/output/*.xml'
</code>```

for the relative to the previous build:

```<code>perfReport relativeFailedThresholdNegative: 10, relativeFailedThresholdPositive: 60, relativeUnstableThresholdNegative: 5, relativeUnstableThresholdPositive: 30, sourceDataFiles: 'resultsJmeter/output/*.xml', filterRegex: ''
</code>```

Body:
I am interested to publish jmeter report in Jenkins and set the pipeline as "failed" if there are degradation in terms of performances between the previous executions.

Below the configuration set in my Jenkinsfile for my jmeter results:

                perfReport filterRegex: '',
                        relativeFailedThresholdNegative: 0,
                        relativeFailedThresholdPositive: 0,
                        relativeUnstableThresholdNegative: 0,
                        relativeUnstableThresholdPositive: 0,
                        sourceDataFiles: 'resultsJmeter/output/*.xml'
                    }

Is there any way to evaluate automatically the previous executions (if any) ?

Body:
As per Performance Trend Reporting article:

You can configure the error percentage thresholds and the relative percentage thresholds which would make the project unstable or failed or set them to -1 to disable the feature

As per How to Use the Jenkins Performance Plugin

Set the following values:

Unstable: 10
Failed: 60

This configuration will mark the build as unstable when errors are at 10% and as failed when 60% of our requests failed.

The relevant pipeline syntax would be:

perfReport errorFailedThreshold: 60, errorUnstableThreshold: 10, filterRegex: '', sourceDataFiles: 'resultsJmeter/output/*.xml'

for the relative to the previous build:

perfReport relativeFailedThresholdNegative: 10, relativeFailedThresholdPositive: 60, relativeUnstableThresholdNegative: 5, relativeUnstableThresholdPositive: 30, sourceDataFiles: 'resultsJmeter/output/*.xml', filterRegex: ''


问:
How would I use PHP substr?
I am trying to figure out how to use substr in my program to get the appropriate data from a table.

User picks 'Letters' "AA", "AB", "AC", "AD", "AE" or "all"

Then I need to compare if the 'panelID' has the 'Letters' I assume using substr.

panelID example: 1122AA-0010

```<code>$_SESSION['yield'] = "
from (select distinct panelID from DATABASE.TABLE) s, DATABASE.TABLE p
where p.panelID = s.panelID and p.laminationts > '$start_date' and p.laminationts < '$end_date'
group by week(p.laminationts)";
</code>```

Something like this

```<code>"where substr(p.panelID,4,2) = substr(s.panelID,4,2) and p.laminationts > '$start_date' and p.laminationts < ..."
</code>```

答:
Another option is to use the LIKE operator and % wildcard. It will find any rows that contain the string of text you are interested in:

http://socialstreams.co/40/MySQL_LIKE_Operator

Title: How would I use PHP substr?

Body:
I am trying to figure out how to use substr in my program to get the appropriate data from a table.

User picks 'Letters' "AA", "AB", "AC", "AD", "AE" or "all"

Then I need to compare if the 'panelID' has the 'Letters' I assume using substr.

panelID example: 1122AA-0010

$_SESSION['yield'] = "
from (select distinct panelID from DATABASE.TABLE) s, DATABASE.TABLE p
where p.panelID = s.panelID and p.laminationts > '$start_date' and p.laminationts < '$end_date'
group by week(p.laminationts)";

Something like this

"where substr(p.panelID,4,2) = substr(s.panelID,4,2) and p.laminationts > '$start_date' and p.laminationts < ..."


问:
Vuejs v-for is working but I can't call local variable
I have a simple html called in hapi back end:

```<code><form id="databinding" action="/config/update" method="post">
  <div class="container">
    <select v-model="extensions.listType" style="width:300px;font-size:25px;">
      <option value="authorized">Inclusion list</option>
      <option value="forbidden">Exclusion list</option>
    </select>
    <ul>
      <li
        v-for="(ext, index) in extensions[extensions.listType]"
        :key="index"
        onclick="console.log(ext)"
      >
        {{ext}}
      </li>
    </ul>

    <button type="submit">Save parameters</button>
  </div>
</form>
<script>
  var vm = new Vue({
    el: "#databinding",
    data() {
      return {
        maxBytes: 5000000,
        extensions: {
          listType: "forbidden",
          forbidden: ["bat", "bin", "chm", "class", "com", "dll"],
          authorized: ["3g2", "3gp", "arf", "asf"]
        }
      };
    }
  });
</script>
</code>```

the v-for element displays the right number of dots but with nothing written with it (see picture). When I log the ext variable, I get "ext is not defined". I tried the same thing with extensions.
It seems like vue's data is ok in the v-for statement, but not after that.

Does someone has an idea of what's happening, I'm running out of solutions.
result of the v-for statement

EDIT

Solved the issue, I just needed to add webpack to render the template

答:
Call the @click handler of vuejs. Now you can call the external function from the method in vuejs. Here is a working example: https://codepen.io/v08i/pen/xxGVQRE

```<code>function logThisExternal(item) {
  console.log(item);
}

new Vue({
  el: '#databinding',
    data () {
    return {
       extensions: {
          listType: "forbidden",
          forbidden: ["bat", "bin", "chm", "class", "com", "dll"],
          authorized: ["3g2", "3gp", "arf", "asf"]
        }
    }
  },
  methods: {
    logThis: function(ext) {
      logThisExternal(ext);
    }
  }
})
</code>```

Template code:

```<code><form id="databinding" action="/config/update" method="post">
 <ul>
      <li
        v-for="(ext, index) in extensions[extensions.listType]"
        :key="index"
        @click="logThis(ext)"
      >
        {{ext}}
      </li>
    </ul>
</form>
</code>```

Note that I have created a function logThisExternal which is being called from the vuejs method logThis

Body:
I have a simple html called in hapi back end:

<form id="databinding" action="/config/update" method="post">

    <select v-model="extensions.listType" style="width:300px;font-size:25px;">
      <option value="authorized">Inclusion list</option>
      <option value="forbidden">Exclusion list</option>
    </select>

        {{ext}}

    <button type="submit">Save parameters</button>

</form>

the v-for element displays the right number of dots but with nothing written with it (see picture). When I log the ext variable, I get "ext is not defined". I tried the same thing with extensions.
It seems like vue's data is ok in the v-for statement, but not after that.

Does someone has an idea of what's happening, I'm running out of solutions.
result of the v-for statement

EDIT

Solved the issue, I just needed to add webpack to render the template

Body:
Call the @click handler of vuejs. Now you can call the external function from the method in vuejs. Here is a working example: https://codepen.io/v08i/pen/xxGVQRE

function logThisExternal(item) {
  console.log(item);
}

new Vue({
  el: '#databinding',
    data () {
    return {
       extensions: {
          listType: "forbidden",
          forbidden: ["bat", "bin", "chm", "class", "com", "dll"],
          authorized: ["3g2", "3gp", "arf", "asf"]
        }
    }
  },
  methods: {
    logThis: function(ext) {
      logThisExternal(ext);
    }
  }
})

Template code:

<form id="databinding" action="/config/update" method="post">
 <ul>
      <li
        v-for="(ext, index) in extensions[extensions.listType]"
        :key="index"
        @click="logThis(ext)"
      >
        {{ext}}
      </li>
    </ul>
</form>

Note that I have created a function logThisExternal which is being called from the vuejs method logThis


问:
Sidekiq - pick up DB changes made by another worker
In a Rails app, I have projects which have many tasks.
A task may have a predecessor that need to be completed before the task can start.

I use sidekiq for creating tasks.

```<code>class ScheduleProjectJob < ApplicationJob
  queue_as :default

  def perform(project)
    tasks = Array(project.tasks)

    while !tasks.empty? do
      task = tasks.shift

      if task.without_predecessor? || task.predecessor_scheduled?
        ScheduleTaskJob.perform_later(task)
      else
        tasks << task
      end
    end
  end
</code>```

I loop through the tasks and schedule a task if it doesn't have a predecessor or, in case it has one, when the predecessor has been already scheduled.

To check if the predecessor has been scheduled, I check in the database if the predecessor state is scheduled (tasks are created with created state and updated to scheduled at the end of ScheduleTaskJob.

The check is as follows

```<code>Task.joins(:task_template).
     where(%q(task_templates.dep_id = :dep AND
              task_templates.tag = :tag AND
              tasks.state = :state),
              specification_id: task_template.dep_id,
              tag: task_template.runs_after_tag,
              state: 'scheduled').
     count > 0
</code>```

The query above seems to work fine when I manually set the DB up and run it.
However, when it runs inside the ScheduleProjectJob the state of the predecessor task is always reported as created even if I can see in the DB the value in the record has been updated to scheduled.

Am I missing anything here?

end

答:
ActiveRecord caches query results, when you're expecting query result to change, wrap your query with:

ActiveRecord::Base.uncached do # or YourModel.uncached do
  some_query.count
end
```

Body:
In a Rails app, I have projects which have many tasks.
A task may have a predecessor that need to be completed before the task can start.

I use sidekiq for creating tasks.

class ScheduleProjectJob < ApplicationJob
  queue_as :default

  def perform(project)
    tasks = Array(project.tasks)

    while !tasks.empty? do
      task = tasks.shift

      if task.without_predecessor? || task.predecessor_scheduled?
        ScheduleTaskJob.perform_later(task)
      else
        tasks << task
      end
    end
  end

I loop through the tasks and schedule a task if it doesn't have a predecessor or, in case it has one, when the predecessor has been already scheduled.

To check if the predecessor has been scheduled, I check in the database if the predecessor state is scheduled (tasks are created with created state and updated to scheduled at the end of ScheduleTaskJob.

The check is as follows

Task.joins(:task_template).
     where(%q(task_templates.dep_id = :dep AND
              task_templates.tag = :tag AND
              tasks.state = :state),
              specification_id: task_template.dep_id,
              tag: task_template.runs_after_tag,
              state: 'scheduled').
     count > 0

The query above seems to work fine when I manually set the DB up and run it.
However, when it runs inside the ScheduleProjectJob the state of the predecessor task is always reported as created even if I can see in the DB the value in the record has been updated to scheduled.

Am I missing anything here?

end


问:
How to stop callback when one evend binds another?
I have tkinter canvas frame in wchich left mouse button is binded to some action

```<code>canvas_frame = tk.Canvas(self)  # Master is tk.Frame

self.canvas_frame.tag_bind('some_tag', '<ButtonPress-1>', self.some_action)

def some_action(self):
    #do something
    self.canvas_frame.bind('<ButtonPress-1>', self.another_action)
</code>```

Whenever i left click some_tag, another action is executed. Even with the first click when another_action is initially binded.

Is there a way to prevent another_action from execution?

答:
There are various ways to do this, whichever is most appropriate will depend on your use case.

Rather than binding self.another_action in the buttonPress-1, bind it in buttonRelease-1.

Bind it as you are doing, but have a local variable in self.another_action which keeps track of the first call and simply does nothing (returns) on the first call.

Rather than setting the binding in buttonPress-1, instead set a variable that indicates the additional binding should be made.  Then make the binding elsewhere, e.g. in the next call by Tk.after()

Body:
I have tkinter canvas frame in wchich left mouse button is binded to some action

canvas_frame = tk.Canvas(self)  # Master is tk.Frame

self.canvas_frame.tag_bind('some_tag', '<ButtonPress-1>', self.some_action)

def some_action(self):
    #do something
    self.canvas_frame.bind('<ButtonPress-1>', self.another_action)

Whenever i left click some_tag, another action is executed. Even with the first click when another_action is initially binded.

Is there a way to prevent another_action from execution?


问:
Relocation R_X86_64_32S against `.bss' can not be used when making a PIE linking error
I'm trying to compile AccNEAT project with CUDA support. It's working fine when I compile it without CUDA support. However, when I compile with CUDA support, I get linker errors. To compile the project, my environment is Ubuntu 18.04 LTS 64 bit with GCC-4.8 and NVCC 6.0.

Linker error:

```<code>/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1
</code>```

The compiler suggests adding a -fPIC option, but I don't know exactly where to put it in the Makefile. I tried to add it using a -XCompiler option like -XCompiler "-fPIC...", but then when I compile I get this error:

```<code>obj/cu/cxx/experiments/maze/mazeevaluator.o: In function `NEAT::create_config(NEAT::Config*&, unsigned long&)':
/home/ner/Projekty/accneat-master-cuda/src/experiments/maze/mazeevaluator.cxx:158: undefined reference to `NEAT::find_resource(std::string const&)'
/home/ner/Projekty/accneat-master-cuda/src/experiments/maze/mazeevaluator.cxx:158: undefined reference to `NEAT::parse_map(std::string)'
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1
</code>```

What does the 'relocation' error mean and is there way to fix this problem?

My Makefile:

```<code>include Makefile.conf

CC_CUDA=nvcc -DENABLE_CUDA ${NVCC_FLAGS} -arch=sm_13 --debug --compiler-bindir ${PFM_NVCC_CCBIN} -Xcompiler "${OPT} ${INCLUDES} ${OPENMP} -I/usr/local/cuda/include "

INCLUDES=$(patsubst %,-I%,$(shell find src -type d))
SOURCES=$(shell find src -name "*.cpp")
CXX_SOURCES=$(shell find src -name "*.cxx")

OBJECTS=${SOURCES:src/%.cpp=obj/cpp/%.o}

LIBS=-lgomp
DEFINES=

ifeq (${ENABLE_CUDA}, true)
    CUDA_SOURCES=$(shell find src -name "*.cu")
    CUDA_OBJECTS=${CUDA_SOURCES:src/%.cu=obj/cu/%.o}
    CUDA_OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cu/cxx/%.o}
    LIBS+=-lcudart
    DEFINES+=-DENABLE_CUDA
else
    OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cpp/cxx/%.o}
endif

DEPENDS=${OBJECTS:%.o=%.d}
DEPENDS+=${CUDA_OBJECTS:%.o=%.d}

ifeq (${DEVMODE}, true)
    OPT=-O0
    #OPENMP=-fopenmp
    MISC_FLAGS=
    NVCC_FLAGS=-G -g
else
    OPT=-O3
    OPENMP=-fopenmp
    MISC_FLAGS=-Werror
endif

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3
.PHONY: clean default

default: ./neat

clean:
    rm -rf obj
    rm -f ./neat
    rm -f src/util/std.h.gch

./neat: ${OBJECTS} ${CUDA_OBJECTS}
    g++ ${PROFILE} ${OBJECTS} ${CUDA_OBJECTS} ${PFM_LD_FLAGS} ${LIBS} -o $@

src/util/std.h.gch: src/util/std.h Makefile.conf Makefile
    g++ ${CC_FLAGS} -std=c++11 $< -o $@

ifeq (${ENABLE_CUDA}, true)

obj/cu/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c -x cu $< -o $@

obj/cu/cxx/%.d: src/%.cxx
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M -x cu $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

obj/cu/%.o: src/%.cu Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c $< -o $@

obj/cu/%.d: src/%.cu
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

else
obj/cpp/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++98 -MMD $< -o $@
endif

obj/cpp/%.o: src/%.cpp Makefile.conf Makefile src/util/std.h.gch
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++11 -MMD $< -o $@

-include ${DEPENDS}
</code>```

(I have added small changes to make it compile like include nvcc dir path).

Build command:

```<code>g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -lgomp -lcudart -o neat
</code>```

EDIT 1: added full build log:

```<code>nerexis@nerexis-GE70-0NC-GE70-0ND:~/Projekty/accneat-master-cuda$ make clean
rm -rf obj
rm -f ./neat
rm -f src/util/std.h.gch
nerexis@nerexis-GE70-0NC-GE70-0ND:~/Projekty/accneat-master-cuda$ make
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 src/util/std.h -o src/util/std.h.gch
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/maze/maze.cpp -o obj/cpp/experiments/maze/maze.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/regex.cpp -o obj/cpp/experiments/static/regex.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/cfg.cpp -o obj/cpp/experiments/static/cfg.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/xor.cpp -o obj/cpp/experiments/static/xor.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/sequence.cpp -o obj/cpp/experiments/static/sequence.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/experiment.cpp -o obj/cpp/experiments/experiment.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovation.cpp -o obj/cpp/innovgenome/innovation.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/trait.cpp -o obj/cpp/innovgenome/trait.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovnodegene.cpp -o obj/cpp/innovgenome/innovnodegene.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovlinkgene.cpp -o obj/cpp/innovgenome/innovlinkgene.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovgenome.cpp -o obj/cpp/innovgenome/innovgenome.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovgenomemanager.cpp -o obj/cpp/innovgenome/innovgenomemanager.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/genomemanager.cpp -o obj/cpp/genomemanager.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/population.cpp -o obj/cpp/population.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/network/cpu/cpunetwork.cpp -o obj/cpp/network/cpu/cpunetwork.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/speciesorganism.cpp -o obj/cpp/species/speciesorganism.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/species.cpp -o obj/cpp/species/species.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/speciespopulation.cpp -o obj/cpp/species/speciespopulation.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/timer.cpp -o obj/cpp/util/timer.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/rng.cpp -o obj/cpp/util/rng.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/util.cpp -o obj/cpp/util/util.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/resource.cpp -o obj/cpp/util/resource.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/map.cpp -o obj/cpp/util/map.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/main.cpp -o obj/cpp/main.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/organism.cpp -o obj/cpp/organism.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/neat.cpp -o obj/cpp/neat.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c src/network/cuda/cudanetwork.cu -o obj/cu/network/cuda/cudanetwork.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c -x cu src/experiments/maze/mazeevaluator.cxx -o obj/cu/cxx/experiments/maze/mazeevaluator.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c -x cu src/experiments/static/staticevaluator.cxx -o obj/cu/cxx/experiments/static/staticevaluator.o
g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -lgomp -lcudart -o neat
/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1
</code>```

EDIT 2:
Makefile:

```<code>include Makefile.conf
CC_CUDA=nvcc -DENABLE_CUDA ${NVCC_FLAGS} -arch=sm_20 --debug --compiler-bindir ${PFM_NVCC_CCBIN} -Xcompiler "${OPT} ${INCLUDES} ${OPENMP} -I/usr/local/cuda/include -L/usr/local/cuda/lib64 "

INCLUDES=$(patsubst %,-I%,$(shell find src -type d))
SOURCES=$(shell find src -name "*.cpp")
CXX_SOURCES=$(shell find src -name "*.cxx")

OBJECTS=${SOURCES:src/%.cpp=obj/cpp/%.o}

LIBS=-lgomp
DEFINES=

ifeq (${ENABLE_CUDA}, true)
    CUDA_SOURCES=$(shell find src -name "*.cu")
    CUDA_OBJECTS=${CUDA_SOURCES:src/%.cu=obj/cu/%.o}
    CUDA_OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cu/cxx/%.o}
    LIBS+=-lcudart
    DEFINES+=-DENABLE_CUDA
else
    OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cpp/cxx/%.o}
endif

DEPENDS=${OBJECTS:%.o=%.d}
DEPENDS+=${CUDA_OBJECTS:%.o=%.d}

ifeq (${DEVMODE}, true)
    OPT=-O0
    #OPENMP=-fopenmp
    MISC_FLAGS=
    NVCC_FLAGS=-G -g
else
    OPT=-O3
    OPENMP=-fopenmp
    MISC_FLAGS=-Werror
    NVCC_FLAGS=--relocatable-device-code=true --dont-use-profile -ldir /usr/local/cuda/nvvm/libdevice
endif

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3 -fPIC
.PHONY: clean default

default: ./neat

clean:
    rm -rf obj
    rm -f ./neat
    rm -f src/util/std.h.gch

./neat: ${OBJECTS} ${CUDA_OBJECTS}
    g++ ${PROFILE} ${OBJECTS} ${CUDA_OBJECTS} ${PFM_LD_FLAGS} -fPIC ${LIBS} -o $@

src/util/std.h.gch: src/util/std.h Makefile.conf Makefile
    g++ ${CC_FLAGS} -std=c++11 $< -o $@

ifeq (${ENABLE_CUDA}, true)

obj/cu/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c -x cu $< -o $@

obj/cu/cxx/%.d: src/%.cxx
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M -x cu $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

obj/cu/%.o: src/%.cu Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c $< -o $@

obj/cu/%.d: src/%.cu
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

else
obj/cpp/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++98 -MMD $< -o $@
endif

obj/cpp/%.o: src/%.cpp Makefile.conf Makefile src/util/std.h.gch
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++11 -MMD $< -o $@

-include ${DEPENDS}
</code>```

Build log (just the end because of length limit):

```<code>g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -fPIC -lgomp -lcudart -o neat
/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against symbol `_ZTVN4NEAT11CudaNetworkE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:50: recipe for target 'neat' failed
make: *** [neat] Error 1
</code>```

EDIT 3: I was able to compile when I have added the options -fPIC -shared to -Xcompiler option and CC_FLAGS and ./neat: g++ line.
When I run compiled binary, I get segmentation fault error.
Additional info from valgrind program:

```<code>==14367== Jump to the invalid address stated on the next line
==14367==    at 0x1C296: ???
==14367==    by 0x12506B: operator<< <std::char_traits<char> > (ostream:561)
==14367==    by 0x12506B: cmp(NEAT::InnovationId const&, NEAT::InnovationId const&) [clone .part.5] (innovation.cpp:43)
==14367==  Address 0x1c296 is not stack'd, malloc'd or (recently) free'd
==14367==
==14367==
==14367== Process terminating with default action of signal 11 (SIGSEGV)
==14367==  Bad permissions for mapped region at address 0x1C296
==14367==    at 0x1C296: ???
==14367==    by 0x12506B: operator<< <std::char_traits<char> > (ostream:561)
==14367==    by 0x12506B: cmp(NEAT::InnovationId const&, NEAT::InnovationId const&) [clone .part.5] (innovation.cpp:43)
==14367==
</code>```

答:
I tred a tip in this thread which suggested adding the following to the nvcc compiler options, which worked for me:

```<code>nvcc --compiler-options -fPIC ...
</code>```

I only just learned that PIC stands for Position Independent Code (meaning that the executable can be loaded anywhere in memory). When compiling a PIC executable, all referenced libraries and objects need to be PIC as well (I think), including the Cuda code. So in my case the fPIC option needed to be passed to nvcc not g++.

Body:
I'm trying to compile AccNEAT project with CUDA support. It's working fine when I compile it without CUDA support. However, when I compile with CUDA support, I get linker errors. To compile the project, my environment is Ubuntu 18.04 LTS 64 bit with GCC-4.8 and NVCC 6.0.

Linker error:

/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1

The compiler suggests adding a -fPIC option, but I don't know exactly where to put it in the Makefile. I tried to add it using a -XCompiler option like -XCompiler "-fPIC...", but then when I compile I get this error:

obj/cu/cxx/experiments/maze/mazeevaluator.o: In function `NEAT::create_config(NEAT::Config*&, unsigned long&)':
/home/ner/Projekty/accneat-master-cuda/src/experiments/maze/mazeevaluator.cxx:158: undefined reference to `NEAT::find_resource(std::string const&)'
/home/ner/Projekty/accneat-master-cuda/src/experiments/maze/mazeevaluator.cxx:158: undefined reference to `NEAT::parse_map(std::string)'
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1

What does the 'relocation' error mean and is there way to fix this problem?

My Makefile:

include Makefile.conf

CC_CUDA=nvcc -DENABLE_CUDA ${NVCC_FLAGS} -arch=sm_13 --debug --compiler-bindir ${PFM_NVCC_CCBIN} -Xcompiler "${OPT} ${INCLUDES} ${OPENMP} -I/usr/local/cuda/include "

INCLUDES=$(patsubst %,-I%,$(shell find src -type d))
SOURCES=$(shell find src -name "*.cpp")
CXX_SOURCES=$(shell find src -name "*.cxx")

OBJECTS=${SOURCES:src/%.cpp=obj/cpp/%.o}

LIBS=-lgomp
DEFINES=

ifeq (${ENABLE_CUDA}, true)
    CUDA_SOURCES=$(shell find src -name "*.cu")
    CUDA_OBJECTS=${CUDA_SOURCES:src/%.cu=obj/cu/%.o}
    CUDA_OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cu/cxx/%.o}
    LIBS+=-lcudart
    DEFINES+=-DENABLE_CUDA
else
    OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cpp/cxx/%.o}
endif

DEPENDS=${OBJECTS:%.o=%.d}
DEPENDS+=${CUDA_OBJECTS:%.o=%.d}

ifeq (${DEVMODE}, true)
    OPT=-O0
    #OPENMP=-fopenmp
    MISC_FLAGS=
    NVCC_FLAGS=-G -g
else
    OPT=-O3
    OPENMP=-fopenmp
    MISC_FLAGS=-Werror
endif

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3
.PHONY: clean default

default: ./neat

clean:
    rm -rf obj
    rm -f ./neat
    rm -f src/util/std.h.gch

./neat: ${OBJECTS} ${CUDA_OBJECTS}
    g++ ${PROFILE} ${OBJECTS} ${CUDA_OBJECTS} ${PFM_LD_FLAGS} ${LIBS} -o $@

src/util/std.h.gch: src/util/std.h Makefile.conf Makefile
    g++ ${CC_FLAGS} -std=c++11 $< -o $@

ifeq (${ENABLE_CUDA}, true)

obj/cu/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c -x cu $< -o $@

obj/cu/cxx/%.d: src/%.cxx
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M -x cu $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

obj/cu/%.o: src/%.cu Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c $< -o $@

obj/cu/%.d: src/%.cu
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

else
obj/cpp/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++98 -MMD $< -o $@
endif

obj/cpp/%.o: src/%.cpp Makefile.conf Makefile src/util/std.h.gch
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++11 -MMD $< -o $@

-include ${DEPENDS}

(I have added small changes to make it compile like include nvcc dir path).

Build command:

g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -lgomp -lcudart -o neat

EDIT 1: added full build log:

nerexis@nerexis-GE70-0NC-GE70-0ND:~/Projekty/accneat-master-cuda$ make clean
rm -rf obj
rm -f ./neat
rm -f src/util/std.h.gch
nerexis@nerexis-GE70-0NC-GE70-0ND:~/Projekty/accneat-master-cuda$ make
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 src/util/std.h -o src/util/std.h.gch
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/maze/maze.cpp -o obj/cpp/experiments/maze/maze.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/regex.cpp -o obj/cpp/experiments/static/regex.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/cfg.cpp -o obj/cpp/experiments/static/cfg.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/xor.cpp -o obj/cpp/experiments/static/xor.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/static/sequence.cpp -o obj/cpp/experiments/static/sequence.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/experiments/experiment.cpp -o obj/cpp/experiments/experiment.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovation.cpp -o obj/cpp/innovgenome/innovation.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/trait.cpp -o obj/cpp/innovgenome/trait.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovnodegene.cpp -o obj/cpp/innovgenome/innovnodegene.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovlinkgene.cpp -o obj/cpp/innovgenome/innovlinkgene.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovgenome.cpp -o obj/cpp/innovgenome/innovgenome.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/innovgenome/innovgenomemanager.cpp -o obj/cpp/innovgenome/innovgenomemanager.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/genomemanager.cpp -o obj/cpp/genomemanager.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/population.cpp -o obj/cpp/population.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/network/cpu/cpunetwork.cpp -o obj/cpp/network/cpu/cpunetwork.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/speciesorganism.cpp -o obj/cpp/species/speciesorganism.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/species.cpp -o obj/cpp/species/species.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/species/speciespopulation.cpp -o obj/cpp/species/speciespopulation.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/timer.cpp -o obj/cpp/util/timer.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/rng.cpp -o obj/cpp/util/rng.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/util.cpp -o obj/cpp/util/util.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/resource.cpp -o obj/cpp/util/resource.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/util/map.cpp -o obj/cpp/util/map.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/main.cpp -o obj/cpp/main.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/organism.cpp -o obj/cpp/organism.o
g++ -Wall  -DENABLE_CUDA -Werror  -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -O3 -c -g -gdwarf-3 -fPIC -std=c++11 -MMD src/neat.cpp -o obj/cpp/neat.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c src/network/cuda/cudanetwork.cu -o obj/cu/network/cuda/cudanetwork.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c -x cu src/experiments/maze/mazeevaluator.cxx -o obj/cu/cxx/experiments/maze/mazeevaluator.o
nvcc -DENABLE_CUDA  -arch=sm_13 --debug --compiler-bindir gcc-4.8 -Xcompiler "-O3 -Isrc -Isrc/experiments -Isrc/experiments/maze -Isrc/experiments/static -Isrc/innovgenome -Isrc/network -Isrc/network/cuda -Isrc/network/cpu -Isrc/species -Isrc/util -fopenmp -I/usr/local/cuda/include -L/usrlocal/cuda/lib64" -c -x cu src/experiments/static/staticevaluator.cxx -o obj/cu/cxx/experiments/static/staticevaluator.o
g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -lgomp -lcudart -o neat
/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:49: recipe for target 'neat' failed
make: *** [neat] Error 1

EDIT 2:
Makefile:

include Makefile.conf
CC_CUDA=nvcc -DENABLE_CUDA ${NVCC_FLAGS} -arch=sm_20 --debug --compiler-bindir ${PFM_NVCC_CCBIN} -Xcompiler "${OPT} ${INCLUDES} ${OPENMP} -I/usr/local/cuda/include -L/usr/local/cuda/lib64 "

INCLUDES=$(patsubst %,-I%,$(shell find src -type d))
SOURCES=$(shell find src -name "*.cpp")
CXX_SOURCES=$(shell find src -name "*.cxx")

OBJECTS=${SOURCES:src/%.cpp=obj/cpp/%.o}

LIBS=-lgomp
DEFINES=

ifeq (${ENABLE_CUDA}, true)
    CUDA_SOURCES=$(shell find src -name "*.cu")
    CUDA_OBJECTS=${CUDA_SOURCES:src/%.cu=obj/cu/%.o}
    CUDA_OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cu/cxx/%.o}
    LIBS+=-lcudart
    DEFINES+=-DENABLE_CUDA
else
    OBJECTS+=${CXX_SOURCES:src/%.cxx=obj/cpp/cxx/%.o}
endif

DEPENDS=${OBJECTS:%.o=%.d}
DEPENDS+=${CUDA_OBJECTS:%.o=%.d}

ifeq (${DEVMODE}, true)
    OPT=-O0
    #OPENMP=-fopenmp
    MISC_FLAGS=
    NVCC_FLAGS=-G -g
else
    OPT=-O3
    OPENMP=-fopenmp
    MISC_FLAGS=-Werror
    NVCC_FLAGS=--relocatable-device-code=true --dont-use-profile -ldir /usr/local/cuda/nvvm/libdevice
endif

CC_FLAGS=-Wall ${DEFINES} ${MISC_FLAGS} ${PROFILE} ${INCLUDES} ${OPENMP} ${OPT} -c -g -gdwarf-3 -fPIC
.PHONY: clean default

default: ./neat

clean:
    rm -rf obj
    rm -f ./neat
    rm -f src/util/std.h.gch

./neat: ${OBJECTS} ${CUDA_OBJECTS}
    g++ ${PROFILE} ${OBJECTS} ${CUDA_OBJECTS} ${PFM_LD_FLAGS} -fPIC ${LIBS} -o $@

src/util/std.h.gch: src/util/std.h Makefile.conf Makefile
    g++ ${CC_FLAGS} -std=c++11 $< -o $@

ifeq (${ENABLE_CUDA}, true)

obj/cu/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c -x cu $< -o $@

obj/cu/cxx/%.d: src/%.cxx
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M -x cu $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

obj/cu/%.o: src/%.cu Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    ${CC_CUDA} -c $< -o $@

obj/cu/%.d: src/%.cu
    @mkdir -p $(dir $@)
    @${CC_CUDA} -M $< > $@.tmp
    @cat $@.tmp | sed 's,.*\.o[[:space:]]*:,$@:,g' | sed 's,\.d,\.o,' > $@
    @rm $@.tmp

else
obj/cpp/cxx/%.o: src/%.cxx Makefile.conf Makefile
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++98 -MMD $< -o $@
endif

obj/cpp/%.o: src/%.cpp Makefile.conf Makefile src/util/std.h.gch
    @mkdir -p $(shell dirname $@)
    g++ ${CC_FLAGS} -std=c++11 -MMD $< -o $@

-include ${DEPENDS}

Build log (just the end because of length limit):

g++  obj/cpp/experiments/maze/maze.o obj/cpp/experiments/static/regex.o obj/cpp/experiments/static/cfg.o obj/cpp/experiments/static/xor.o obj/cpp/experiments/static/sequence.o obj/cpp/experiments/experiment.o obj/cpp/innovgenome/innovation.o obj/cpp/innovgenome/trait.o obj/cpp/innovgenome/innovnodegene.o obj/cpp/innovgenome/innovlinkgene.o obj/cpp/innovgenome/innovgenome.o obj/cpp/innovgenome/innovgenomemanager.o obj/cpp/genomemanager.o obj/cpp/population.o obj/cpp/network/cpu/cpunetwork.o obj/cpp/species/speciesorganism.o obj/cpp/species/species.o obj/cpp/species/speciespopulation.o obj/cpp/util/timer.o obj/cpp/util/rng.o obj/cpp/util/util.o obj/cpp/util/resource.o obj/cpp/util/map.o obj/cpp/main.o obj/cpp/organism.o obj/cpp/neat.o obj/cu/network/cuda/cudanetwork.o obj/cu/cxx/experiments/maze/mazeevaluator.o obj/cu/cxx/experiments/static/staticevaluator.o  -fPIC -lgomp -lcudart -o neat
/usr/bin/x86_64-linux-gnu-ld: obj/cu/network/cuda/cudanetwork.o: relocation R_X86_64_32S against symbol `_ZTVN4NEAT11CudaNetworkE' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/maze/mazeevaluator.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: obj/cu/cxx/experiments/static/staticevaluator.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/x86_64-linux-gnu-ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
Makefile:50: recipe for target 'neat' failed
make: *** [neat] Error 1

EDIT 3: I was able to compile when I have added the options -fPIC -shared to -Xcompiler option and CC_FLAGS and ./neat: g++ line.
When I run compiled binary, I get segmentation fault error.
Additional info from valgrind program:

==14367== Jump to the invalid address stated on the next line
==14367==    at 0x1C296: ???
==14367==    by 0x12506B: operator<< <std::char_traits<char> > (ostream:561)
==14367==    by 0x12506B: cmp(NEAT::InnovationId const&, NEAT::InnovationId const&) [clone .part.5] (innovation.cpp:43)
==14367==  Address 0x1c296 is not stack'd, malloc'd or (recently) free'd
==14367==
==14367==
==14367== Process terminating with default action of signal 11 (SIGSEGV)
==14367==  Bad permissions for mapped region at address 0x1C296
==14367==    at 0x1C296: ???
==14367==    by 0x12506B: operator<< <std::char_traits<char> > (ostream:561)
==14367==    by 0x12506B: cmp(NEAT::InnovationId const&, NEAT::InnovationId const&) [clone .part.5] (innovation.cpp:43)
==14367==

Body:
I tred a tip in this thread which suggested adding the following to the nvcc compiler options, which worked for me:

nvcc --compiler-options -fPIC ...

I only just learned that PIC stands for Position Independent Code (meaning that the executable can be loaded anywhere in memory). When compiling a PIC executable, all referenced libraries and objects need to be PIC as well (I think), including the Cuda code. So in my case the fPIC option needed to be passed to nvcc not g++.


问:
Ask about char in array
example

```<code>char names[2][5] = {"john","boy"};
</code>```

I want to ask about char 2 dimension array in c, in [2] i mean, it's explaining about total element of array, and [5] i mean, it's explaining about length of character in array

So, is it true how to use array 2 dimension in c ?

Sorry for my bad english

答:
Consider a table of 2 * 5, where you get 2 rows, each of 5 columns. Here 2 dimensional array contains 2 rows i.e 2 char*. Each row is of size 5

Outputs:

```<code>names[0][0] = 'j'
names[1][0] = 'b'
name[0] = "john"
name[1] = "boy"
</code>```

Title: Ask about char in array

Body:
example

char names[2][5] = {"john","boy"};

I want to ask about char 2 dimension array in c, in [2] i mean, it's explaining about total element of array, and [5] i mean, it's explaining about length of character in array

So, is it true how to use array 2 dimension in c ?

Sorry for my bad english

Body:
Consider a table of 2 * 5, where you get 2 rows, each of 5 columns. Here 2 dimensional array contains 2 rows i.e 2 char*. Each row is of size 5

Outputs:

names[0][0] = 'j'
names[1][0] = 'b'
name[0] = "john"
name[1] = "boy"


答:
names is an array of two elements, each element is in turn an array of five elements.

And you use each array like you would any other. So the firs element of names is names[0], the second is names[1]. Then the first element of names[0] is names[0][0], the second names[0][1], etc.

Also, because each element of names is an array, and each of those two arrays are initialized as null-terminated strings, you can use names[0] and names[1] like any other string.

Title: Ask about char in array


答:
You can create easily a Pivot Table:

More about Pivot
  Tables

To create this Pivot Table I did:

Date field into Rows Section and grouped by Years and Months

Visits field into Values section and selected option MAX

Group Pivot Tables
  Items

Title: Max Value of a column in the same year and month

Body:
I have to columns I want to analyse, visits and dates. I now want the max visits of a month. The data ranges over multiple years.

+--------+--------+---+
|Date    |Visits  |Max|
|31.12.19|77      |77 |
|01.01.20|47      |   |
|02.01.20|121     |   |
|03.01.20|133     |133|
...
|01.02.20|21      |   |
|02.02.20|135     |135|
+--------+--------+---+