我尝试在一个项目中使用gsl库,但我无法从gsl网站上正常运行示例程序.源代码和所有命令均来自网站:https://www.gnu.org/software/gsl/manual/html_node/Using-the-library.html#Using-the-library
该程序如下(test.cpp):
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main (void) {
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我首先编译没有错误.但链接失败:
$ g++ -Wall -I/usr/include/ -c test.cpp
$ g++ -L/usr/lib/ -lgsl -lgslcblas -lm test.o
test.o: In function `main':
test.cpp:(.text+0x1c): undefined reference to `gsl_sf_bessel_J0'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
但图书馆可用:
$ ll /usr/lib/libgsl*
lrwxrwxrwx 1 root root 16 Mar 2 2012 /usr/lib/libgsl.so.0 -> libgsl.so.0.16.0
lrwxrwxrwx 1 root root 16 …Run Code Online (Sandbox Code Playgroud) 我有一个向量对,我希望仅按键(可能会出现多次)稳定排序。我不使用 amultimap来实现这一点,因为它不是明确稳定的。因此,我提供了一个自定义比较函数stable_sort。我现在正在努力将该函数模板化。下面是一个简短的测试实现,向您展示用例:
#include <iostream>
#include <algorithm>
#include <vector>
#include "test.h"
using namespace std;
int main() {
typedef pair<int, int> TPair;
vector<TPair> data(10);
data[0] = make_pair(7, 1);
data[1] = make_pair(3, 2);
data[2] = make_pair(8, 0);
data[3] = make_pair(5, 1);
data[4] = make_pair(3, 1);
data[5] = make_pair(2, 0);
data[6] = make_pair(7, 0);
data[7] = make_pair(6, 0);
data[8] = make_pair(5, 0);
data[9] = make_pair(3, 0);
stable_sort(data.begin(), data.end(), comp1);
for (unsigned int i = 0; i < 10; ++i) { …Run Code Online (Sandbox Code Playgroud) 我正在使用Google People API来访问我的联系人。
我在Google Developers Console中激活了它,并创建了一个项目,一个服务帐户(以结尾....iam.gserviceaccount.com)和一个以JSON格式存储的身份验证密钥。
当我访问联系人时,似乎使用了我的服务帐户地址而不是我的Google帐户的联系人,从而导致列表为空。
如何告诉API使用我的帐户而不是服务帐户?
这是我到目前为止的代码:
from google.oauth2 import service_account
from googleapiclient.discovery import build
# pip install google-auth google-auth-httplib2 google-api-python-client
SCOPES = ['https://www.googleapis.com/auth/contacts.readonly']
KEY = '~/private.json'
credentials = service_account.Credentials.from_service_account_file(
KEY, scopes=SCOPES)
service = build(
serviceName='people', version='v1', credentials=credentials)
connections = service.people().connections().list(
resourceName='people/me', personFields='names').execute()
print(connections)
# result: {}
Run Code Online (Sandbox Code Playgroud) python google-api oauth-2.0 google-api-python-client google-people