Android中configure: error: C compiler cannot create executables解决方法

软硬件环境

  • android 5.1..1
  • ndk r15c

错误描述

vlc_android_compile_error_01

vlc_android_compile_error_02

解决思路

这个一般是跟ndk相关的错误,某些头文件或者obj文件找不到。可以编写个简单的hello world源文件测试

#include <stdio.h>

int main() {
    printf("Hello world.");
    return 0;
}

使用ndk中的编译器进行编译,如

export $ANDROID_NDK=/home/longjing/tools/Android/android-ndk-r15c
$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc test.c

编译果然报错,找不到头文件

../test.c:16:19: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
                   ^
compilation terminated.

既然是测试文件,那干脆就去掉include语句,再删除printf语句,重新编译看下结果

//#include <stdio.h>

int main() {
    //printf("Hello world.");
    return 0;
}

这下就告诉你obj文件找不到了

/home/longjing/tools/Android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtbegin_dynamic.o: No such file or directory
/home/longjing/tools/Android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot open crtend_android.o: No such file or directory
/home/longjing/tools/Android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lc
/home/longjing/tools/Android/android-ndk-r15c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -ldl
collect2: error: ld returned 1 exit status

使用find命令在ndk目录下搜索下crtend_android.o文件

cd /home/longjing/tools/Android/android-ndk-r15c
find . -iname crtend_android.o

vlc_android_compile_error_03

可以看到,obj文件都是存在的。那么怎么解决呢?既然找不到,那就给你个路径

$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc test.c --sysroot=$ANDROID_NDK/platforms/android-9/arch-arm

最后重新编译,错误消失了。

pyinstaller打包sqlalchemy问题的解决方法

软硬件环境

  • python3
  • sqlalchemy
  • pyintaller 3.2.1

问题描述

最近在用pyinstaller打包一个使用了sqlalchemy库的python3工程中,碰到了打包后的可执行文件报错的问题,如下图所示

pyinstaller_sqlalchemy_error

解决方案

将sqlalchemy.dialects中的mysql引入,然后采用mysql+pymysql的方式打开数据库,代码如下

import pymysql

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.dialects import mysql

username = 'djstava'
passwd = '123456'
server = '192.168.0.100'
port = '3306'
dbname = 'djdb'

cmd_connect = 'mysql+pymysql://{}:{}@{}:{}/{}'.format(username, passwd, server, port, dbname)

engine = create_engine(cmd_connect)

pyinstaller打包命令

pyinstaller -F --clean --distpath shark main.py

其中shark是目标文件夹,main.py是工程入口文件,-F表示生成一个可执行文件.

参考资料

如何修复linux系统中的grub?

Environment

  • ubuntu
  • grub

Intro

The rescue mode is a major GRUB 2 enhancement. If GRUB 2 fails to find a useable grub.cfg and is unable to transfer control to a kernel it will drop to a grub-rescue> prompt. From this prompt the user can investigate problems, make changes, and retry the boot.

Steps

ls

This will display the known devices and partitions. From this information, the user must determine the device and partition on which the system is installed.

set prefix=(hdX,Y)/boot/grub

If incorrect, "no such disk" or "not found" errors will occur later.

set root=(hdX,Y)********

In this command, X is the device/drive, starting with 0. Y is the partition, starting with 1. Example: (hd0,1) is sda1. (hd2,5) is sdc5.

set

Inspect the "prefix=" listing. It should match the root designation in Step 3, in the following format: prefix=(hdX,Y)/boot/grub.

ls /boot

Inspect the contents. The user should see varioius kernels, initrd images and the grub folder. If not, use the ls command to inspect the device and attempt to find these files and folders. If necessary, set another device as root.

insmod /boot/grub/linux.mod

Load (insert module) the linux module. Without this module loaded, the user will receive an "Unknown command linux" message when trying to load the kernel.

linux /vmlinuz root=/dev/sdXY ro

Load the linux kernel, substituting the correct designations for "X" and "Y" (example: sda1). The user will see a message showing the kernel has been loaded.

initrd /initrd.img

Load the initrd image. When pressing ENTER the user may or may not see a message in the terminal.

boot

Attempt to boot using the information entered.

These changes are not permanent. After successfully booting into the system the user should run sudo update-grub and inspect the GRUB 2 configuration file (/boot/grub/grub.cfg).The user may need to reinstall GRUB 2 using sudo grub-install /dev/sdX.

分享python3爬虫及数据分析实战视频教程

软硬件环境

  • python3

分享

来自付费资源,这里分享给需要的朋友。视频基于python3,2016年底录制,由浅入深,结合实战案例,内容比较丰富。有需要的朋友请在评论里留下邮箱地址,我会一一回复,免费提供。

video_01

video_02

python3接收udp视频数据

软硬件环境

  • ubuntu 16.04 64bit
  • python3
  • udp数据源

参考源码

# -*- coding: utf-8 -*-

"""
@author: djstava
@license: MIT Licence 
@contact: djstava@gmail.com
@site: http://www.xugaoxiang.com
@software: PyCharm
@file: main.py
@time: 8/15/17 5:58 PM
"""

import os
import sys
import socket
import struct

# 组播地址
ip = '225.0.0.1'

# 组播端口
port = 9001

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

# bind的参数是一个元祖tuple
sock.bind((ip, port))

sock_value = struct.pack('4sl', socket.inet_aton(ip), socket.INADDR_ANY)

# 加入udp组播组
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, sock_value)

fileName = 'test.ts'

# 打开文件
fd = open(fileName, 'ab')

while True:
    data = sock.recv(1024000)
    fd.write(data)

# 关闭文件
fd.flush()
fd.close()

# 释放socket
sock.close()