小编Ata*_*xia的帖子

编译OpenGL程序GL/glew.h缺失

我按照本教程中的说明将OpenGL安装到运行Linux Mint的计算机上.我正在尝试编译一个使用OpenGL的程序,但是我遇到了编译错误:fatal error: GL/glew.h: No such file or directory.我检查/ usr/include/GL文件夹,确实缺少glew.h.我不知道为什么它丢失了,因为我做了命令sudo apt-get install libglew1.5并且它给出了输出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libglew1.5 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 465 not upgraded.
Run Code Online (Sandbox Code Playgroud)

为什么缺少glew.h文件?

linux opengl glew

33
推荐指数
2
解决办法
5万
查看次数

在Linux中使用signal.h编译错误

我正在编写一个必须处理信号的shell程序.我的相关信号处理相关代码如下:

#include <signal.h>
...
#include <sys/types.h>
...
void installSigactions( int, struct sigaction* );

void handler_function( int signal_id );
...
/*define signal table*/
struct sigaction signal_action;

/*insert handler function*/
signal_action.sa_handler = handler_function;

/*init the flags field*/
 signal_action.sa_flags = 0;

/*are no masked interrupts*/
sigemptyset( &signal_action.sa_mask );

/*install the signal_actions*/
sigaction( SIGINT, &signal_action, NULL );
Run Code Online (Sandbox Code Playgroud)

编译给我以下警告和错误:

gcc -Wall -ggdb -ansi -static -pedantic -o os1shell2 os1shell2.c
os1shell2.c:35: warning: 'struct sigaction' declared inside parameter list
os1shell2.c:35: warning: its scope is only this definition or …
Run Code Online (Sandbox Code Playgroud)

c linux signals system-calls signal-handling

15
推荐指数
1
解决办法
2万
查看次数

检查目录是否是git存储库(无需cd进入)

我可以使用什么shell命令,使用完整目录路径,确定给定目录是否是git存储库?具体来说,我希望能够在不在目录中的情况下完成此操作,而无需cd进入它.我还希望能够使用一个返回简单"true"或"false"的命令(就像rev-parse --is-inside-work-tree那样),但它不是一个要求.

linux git bash

15
推荐指数
2
解决办法
7125
查看次数

辅助函数应该在标题中还是在实现文件中?

在C++中为类编写辅助方法时,是否应该在标题(.h)文件的类定义中将其声明为私有方法?例如:

/*Foo.h*/
class Foo {

     public:
         int bar();

     private:
         int helper();
};
...
/*Foo.cpp*/
...
int foo::bar() {
    int something = this->helper();
}

int foo::helper() {
    ...
}
Run Code Online (Sandbox Code Playgroud)

或者,最好不要将它声明为类的私有成员,而只是使它成为实现中的独立函数?

/*Foo.h*/
class Foo {
    public:
        int bar();
};
...
/*Foo.cpp*/
...
int Foo::bar() {
    int something = helper();
    ...
}

int helper() {
    ...   
}
Run Code Online (Sandbox Code Playgroud)

c++ oop coding-style

14
推荐指数
1
解决办法
1万
查看次数

写或打印,哪个更快?

完成以下测试后:

for( i = 0; i < 3000000; i++ ) {
    printf( "Test string\n" );
}

for( i = 0; i < 3000000; i++ ) {
    write( STDOUT_FILENO, "Test string\n", strlen( "Test string\n" ) );
}
Run Code Online (Sandbox Code Playgroud)

事实证明,对printf的调用总共需要3秒钟,而写入调用需要花费46秒.如何,所有花哨的格式化魔法printf,以及它printf本身所称的事实,write这可能吗?有什么东西我不见了吗?

任何和所有的想法和意见都表示赞赏.

c unix io performance system-calls

12
推荐指数
2
解决办法
8252
查看次数

马哈拉诺比斯距离反演协方差矩阵

我正在编写一个函数来获取两个向量之间的Mahalanobis距离.我知道这是使用等式a'*C ^ -1*b实现的,其中a和b是向量而C是协方差矩阵.我的问题是,有没有一种有效的方法来找到矩阵的逆矩阵而不使用Gauss-Jordan消除,或者没有办法解决这个问题?我正在寻找一种方法来做到这一点,而不是任何预定义的功能.

我知道C是一个Hermitian,正定矩阵,所以有什么方法可以算法利用这个事实吗?或者是否有一些聪明的方法计算马哈拉诺比斯距离而不计算协方差的倒数?任何帮助,将不胜感激.

***编辑:上面的马哈拉诺比斯距离方程是不正确的.它应该是x'*C ^ -1*x,其中x =(ba),而b和a是我们试图找到距离的两个向量(感谢LRPurser).因此,所选答案中提出的解决方案如下:

d = x'*b,其中b = C ^ -1*x C*b = x,因此使用LU分解或LDL'分解求解b.

c algorithm matrix linear-algebra

8
推荐指数
2
解决办法
4233
查看次数

菜单没有出现在Fragment中

我正在尝试将菜单放入我的应用程序中的片段中.但是,当我运行它时,菜单不会出现.我对在片段中显示菜单所涉及的步骤的理解(如果我错了或缺少某些内容,请纠正我)是您执行以下操作:

  • 在res/menu目录中创建菜单资源文件.
  • 覆盖onCreateOptionsMenu(Menu, MenuInflater)并在所述方法内,膨胀由菜单资源ID定义的布局.
  • onCreateOptionsMenu通过调用setHasOptionsMenu(true)片段的onCreate方法通知片段管理器该片段应该接收调用.

我已经编写了我的代码的简化版本,只包括(我相信)应该显示菜单的最低限度.谁能告诉我这段代码中缺少什么?

这是我的菜单资源xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/menu_item_1"
        android:icon="@android:drawable/ic_menu_add"
        android:title="@string/menu_item_text"
        android:showAsAction="ifRoom|withText"/>
</menu>
Run Code Online (Sandbox Code Playgroud)

我的片段代码:

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;

public class MainFragment extends Fragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setHasOptionsMenu(true);
    }

    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        super.onCreateOptionsMenu(menu, inflater);
        inflater.inflate(R.menu.fragment_menu, menu);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
        View v = …
Run Code Online (Sandbox Code Playgroud)

android menu android-fragments

6
推荐指数
1
解决办法
4087
查看次数

在Linux上安装Freeglut

我正在尝试在运行Linux Mint的计算机上安装freeglut.我按照本网站上的步骤操作:http://freeglut.sourceforge.net/docs/install.php.当我make all在src目录中时,它会给出以下错误:

fatal error: GL/gl.h

此错误由../include/GL/freeglut_std.h给出.检查时,include/GL目录确实没有任何gl.h文件.它也缺少glu.h,freeglut_std.h也试图这样做#include.我该怎么办?为什么缺少gl.h和glu.h?

linux opengl install freeglut linux-mint

4
推荐指数
2
解决办法
1万
查看次数

不能在linux中使用SOIL薄荷

我正在做一项要求我使用SOIL的作业.我使用命令安装它sudo apt-get install libsoil-dev,但当我尝试编译我的程序时,我收到以下错误:

textureMain.cpp:19:18: fatal error: SOIL.h: No such file or directory
compilation terminated.
textureParams.cpp:17:18: fatal error: SOIL.h: No such file or directory
compilation terminated.
Run Code Online (Sandbox Code Playgroud)

为什么即使我安装了SOIL,我也无法编译程序?

c++ linux opengl soil

4
推荐指数
1
解决办法
3069
查看次数

如何通过更改按引用传递的参数来对调用具有副作用的函数的方法进行单元测试?

我有一个方法可以调用内置的 PHP 函数openssl_random_pseudo_bytes.

public function generateRandomBytes()
{
    $crypto_secure = TRUE;

    // $crypto_secure is passed by reference and will be set to FALSE by
    // openssl_random_pseudo_bytes if it uses an insecure algorithm
    $random_bytes = openssl_random_pseudo_bytes(16, $crypto_secure);
    if (!$crypto_secure)
    {
        throw new Security_Exception('Random bytes not generated by a cryptographically secure PRNG algorithm');
    }
    return $random_bytes;
}
Run Code Online (Sandbox Code Playgroud)

我有一个 PHPUnit 测试用例来测试这个方法(它所做的只是验证随机生成的字符串是 16 个字节长)。

public function testRandomBytesLength()
{
    $myclass = new MyClass();

    $this->assertEquals(16, strlen($myclass->generateRandomBytes()));
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何测试$crypto_secureFALSE 并且必须抛出异常的情况?由于此值作为对 的引用传入并修改openssl_random_pseudo_bytes,因此我不确定如何获得此执行路径的测试覆盖率。我的第一个想法是,也许有一个 php.ini …

php random phpunit unit-testing pass-by-reference

4
推荐指数
1
解决办法
348
查看次数

将 PEM 格式的公钥传递给 openssl_pkey_get_public 会出现错误:0906D06C:PEM 例程:PEM_read_bio:无起始行

以下 PEM 格式的 RSA 公钥已提供给 openssl_pkey_get_public。

-----BEGIN PUBLIC KEY-----
MIIBITANBgkqhkiG9w0BAQEFAAOCAQ4AMIIBCQKCAQCIZouo/rL5IkIIGrke/qkY
Nsb9JDXUw2MfutYdwIVjPiEbAcLiVxK6tOVXy7dq+hU0zyNd68bUi7VJjXWoiepS
+Mm6v76GCGvVvno48m7ofWIq6VLEaMQjIM/pzkF0TW7CmtjKvgg722Hx87AI/KCM
sWuHjhcQZsMgV4ibC8EAY6GYwHYAPWfUq+LI2wfRsQHumFC2IuT4guO/Vs5FJGXw
Arrvv7VPyKwZ8cpcZn9ka1K0N7su7QiGnzOhS3n2THaj25alE6TMXnrKmt6yIiXh
amsKVEKPPzHpw9ldTao1aG7vVNC9QXC8i9uQTWhhokxvSNw5OYFFkDZC5jD7McvB
AgMBAAE=
-----END PUBLIC KEY-----
Run Code Online (Sandbox Code Playgroud)

但是,方法调用失败,返回 false,并显示错误字符串error:0906D06C:PEM routines:PEM_read_bio:no start line

公钥无效吗?作为记录,我的代码从公钥模数和指数开始,并使用此处发布的算法将其转换为 PEM 格式发布的算法将其转换为 PEM 格式。

这是完整的脚本:

<?php

function createPemFromModulusAndExponent($n, $e)
{
    $modulus = urlsafeB64Decode($n);
    $publicExponent = urlsafeB64Decode($e);
    $components = array(
        'modulus' => pack('Ca*a*', 2, encodeLength(strlen($modulus)), $modulus),
        'publicExponent' => pack('Ca*a*', 2, encodeLength(strlen($publicExponent)), $publicExponent)
    );

    $RSAPublicKey = pack('Ca*a*a*', 48, encodeLength(strlen($components['modulus']) + strlen($components['publicExponent'])), $components['modulus'], $components['publicExponent']);

    $rsaOID = pack('H*', '300d06092a864886f70d0101010500');
    $RSAPublicKey = chr(0) . $RSAPublicKey;
    $RSAPublicKey = …
Run Code Online (Sandbox Code Playgroud)

php openssl cryptography rsa

2
推荐指数
1
解决办法
1937
查看次数