Python Networking does not compile - transcrypt

I cannot use the python socket module
It says:
C:\Users\Owner\Desktop\Coding Projects\chatserver>Transcrypt import_test.py -b
Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.6.4
Copyright (C) Geatec Engineering. License: Apache 2.0
Error in program import_test.py, module _socket, line 49:
Attempt to load module: _socket
Can't find any of:
C:/Users/Owner/Desktop/Coding Projects/chatserver/__javascript__/_socket.mod.js
C:/Users/Owner/Desktop/Coding Projects/chatserver/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/lib/site-packages/transcrypt/modules/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/lib/site-packages/transcrypt/modules/__javascript__/_socket.mod.js
C:/Program Files (x86)/Python36-32/Scripts/__javascript__/_socket.mod.js
C:/Program Files (x86)/Python36-32/Scripts/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/python36.zip/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/python36.zip/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/DLLs/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/DLLs/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/lib/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/lib/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/lib/site-packages/__javascript__/_socket.mod.js
c:/program files (x86)/python36-32/lib/site-packages/__javascript__/_socket.mod.js
Aborted
Python File:
class Test:
def __init__(self):
print("HI")
try:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except Exception as ex:
print("Error: " + str(ex))

With repect to importing modules like sockets note the following points:
Transcrypt is a compiler rather than an interpreter. This means that imports are done compile time, to be able to compile also the imported modules and include them in the generated code. Since they are compile-time, they cannot be runtime conditional, generate runtime exceptions etc..
If you need compile time condional imports use __pragma__ ('ifdef', ... which works compile time.
You'll need websockets rather than the CPython sockets module, which is probably written in C, hence cannot run in a browser. Since you can use any JS library or API function, you can use e.g. HTML5 web sockets or any JS socket lib. Just use it exactly the same as from JavaScript.
In general, for Transcrypt, use JS libraries, since they're most suited to do their work in the browser.
See also: http://www.transcrypt.org/docs/html/what_why.html#the-ecosystem-different-batteries
[EDIT]
Further clarification:
You should use the Python websockets package only on the server side, so not with Trancrypt.
What I meant is that on the client you should use JavaScript websockets functionality as decribed a.o. at the following locations:
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
https://www.tutorialspoint.com/html5/html5_websocket.htm
http://www.developerfusion.com/article/143158/an-introduction-to-websockets/
Since these are JavaScript facilities, they won't require sys or things like that.
So take care NOT to import websockets in your Transcrypt client code, since this will give you the Python package, rather than the JavaScript facility that is available natively.

Related

Linking libxml with MinGW using OMNETPP shell on windows 10

How can I link libxml on MinGW when using an omnetpp shell?
I am using omnetpp on a windows 10 machine.
My problem happens when I am trying to install the 3rd party package from here
I think that there is a problem in the Makefile failing to locate the libxml library
Following Rudi's answer (following the question) I changed the Makefile libxml path to I/mingw64/include/libxml2 but I still
get a undefined reference to 'xmlFunctionName' error (for many function names)
I tried to isolate the problem and to compile a sample of code from libxml2
Following the compilation guide: using gcc `xml2-config --cflags --libs` -o tree2 tree2.c
I got a fatal error: 'libxml/parser.h' file not found
When I replaced xml2-config --cflags --libs with -I/mingw64/include/libxml2
I got the same error as before undefined reference to 'xmlFunctionName'
what can I do to resolve that issue?
To this specific problem: libxml2 is actually already present as OMNET 5.x also uses it. All dependencies and tools are available in the tools/win64/mingw64 directory. The problem is that (for unknown reasons) the include file of the include/libxml2/libxml folder. The configure script correctly detects this and makes it available in the Makefile.inc as XML_CFLAGS= = -I/mingw64/include/libxml2
This must be added to the compiler flags for each file where you want to use the XML parser. (the library files are in the /mingw64/lib folder) so those are detected and can be used without additional config.
Generally, third party libraries should be available in the /mingw64/include and /mingw64/lib folders. You can either copy them manually there or try to install it with the mingw package manager (however that will most likely ruin your omnet installation as mingw64 is not particularly consistent and it is a rolling release - i.e. this is highly not recommended).

Cannot load lua dll module

I cannot load a lua module, which is a 32bit c++ dll.
The lua module and the lua code is in the same folder.
in c++ code:
extern "C" __declspec(dllexport) int luaopen_luartmidi(lua_State *L) {
...
}
lua first line:
local luartmidi = require 'luartmidi'
When i run the lua code with vs code lua 32bit debugger i get
error message:
Exception has occurred: [C]:-1: error loading module ... from file ...
The specified function could not be found
Dependency Walker says LUA.DLL is missing. When i copy lua.dll in the same folder i get error
c:Users/xyz/.vscode/extensions/actboy168.lua-debug-1.23.1/runtime/win32/lua53/lua.exe: multiple Lua VMs detected
This happens when you link with a lua interpreter statically and then try to load an external module that links against a Lua DLL (and expects a lua.dll or similarly named library to be present). You can't both have a statically compiled interpreter and one loaded from a DLL to be present in the same process (the "multiple Lua VMs detected" message is triggered by a check against this condition).
You have three options:
Compile everything statically (don't load any external modules)
Compile everything dynamically (don't link the Lua interpreter statically)
Use a proxy library that will forward API calls from external libraries to statically linked Lua interpreter (will require exporting Lua symbols and writing a proxy library). See http://lua-users.org/wiki/LuaProxyDllFour links for the code and details (it's for Lua 5.1, but you can tweak the script for Lua 5.3).

Cmake Could not find wxWigets

I want to compile a source code on windows using CMake, it uses wxWigets library.
I downloaded the wxWigets from the page: https://www.wxwidgets.org/
After building by Visual Studio, I got the library /lib file.
I have already set PATH for wxWidgets_LIBRARIES and wxWidgets_INCLUDE_DIRS. But the following errors cannot be resolved.
CMake Error at C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS)
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.11/Modules/FindwxWidgets.cmake:953 (find_package_handle_standard_args)
CMakeLists.txt:52 (find_package)
I also read the thread about this problem in: CMake could not find wxWidgets on Windows
But there is no solution for my case.
You may specify wxWidgets_ROOT_DIR variable to point to your wxWidgets installation.
As far as I understand, you may set either CMake variable via -D option to cmake:
cmake -DwxWidgets_ROOT_DIR:PATH=D:/path/to/wxWidgets/ ...
or you may set environment variable
set wxWidgets_ROOT_DIR=D:\path\to\wxWidgets\ ...
(Note that CMake path variables use "universal" directory separator '/', but environment variables use native directory separator, '\' for Windows).
This variable is described in documentation for FindwxWidget.
Using wxWidgets_LIB_DIR variable could be tricky, see that question.
I have a solution witch can solve this problem.
there is something wrong with the FindwxWidgets.cmake File
Firstly, delete the file
C:/Program Files/CMake/share/cmake-3.11/Modules/FindwxWidgets.cmake
instead, you can find the package by using wxWidetsConfig.cmake file
YOUR_PATH\wxWidgets\lib\cmake\wxWidgets\wxWidgetsConfig.cmake.
add the flowing codes in your CMakeLists.txt and you can use wxWidgets
# set(CMAKE_PREFIX_PATH C:/dev/wxWidgets) also works
set(CMAKE_PREFIX_PATH C:/dev/wxWidgets/lib/cmake/wxWidgets)
find_package(wxWidgets COMPONENTS core base REQUIRED)
add_executable(wxwdemo WIN32 main.cpp)
target_link_libraries(wxwdemo ${wxWidgets_LIBRARIES})
target_include_directories(wxwdemo PUBLIC ${wxWidgets_INCLUDE_DIRS})
then it works

could not find the following boost libraries

I am not able to figure out why am I getting this error.
CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modules/FindBoost.cmake:1753 (message):
Unable to find the requested Boost libraries.
Boost version: 1.48.0
Boost include path: D:/Shark/boost_1_48_0
Could not find the following Boost libraries:
boost_system
boost_date_time
boost_filesystem
boost_program_options
boost_serialization
boost_thread
boost_unit_test_framework
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
Call Stack (most recent call first):
CMakeLists.txt:146 (find_package)
CMake Error at CMakeLists.txt:154 (message):
Please make sure Boost 1.48.0 is installed on your system
It says, Unable to find requested boost library. But I have installed boost 1.48.0 and build it using Visual studio console, and have passed BOOST_LIBRARYDIR=D:/Shark/boost_1_48_0/stage/lib and BOOST_ROOT=D:/Shark/boost_1_48_0.
CMake's FindBoost macros look for the libs in various spots based on the compiler your using. Even if you specify BOOST_LIBRARYDIR, you still have to conform to the standards the FindBoost macro expects for filenames ie:
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_COMPILER}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION}
${Boost_LIB_PREFIX}boost_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}
${Boost_LIB_PREFIX}boost_${COMPONENT} )
Example filenames matching this template for visual studio 2013 (aka msvc 12)
$BOOST_LIBRARY_DIR/boost_atomic-vc120-mt-1_58.dll
$BOOST_LIBRARY_DIR/boost_atomic-vc120-mt-gd-1_58.dll
You'll note that the mt for multithreaded build and the gd to indicate it's a debug build. FindBoost is fussy and will look for the debug build if your CMake project has a CMAKE_BUILD_TYPE=Debug
Additionally if your building multithreaded you'll need to define:
Boost_USE_MULTITHREADED=ON
If your still having trouble you define: Boost_DEBUG=1 and you'll see a lot of additional output about how and where FindBoost is searching.
I was building the boost library by downloading source file. The problem was it was not creating .dll (only .lib).
I downloaded boost binary and installed it from installer to get those files, and set the path BOOL_LIBRARYDIR=C:/local/boost/lib64-msvc-14.0 and BOOL_ROOT=C:/local/boost to make it done.

Linking APR (Apache Portable Runtime) with CMake in Windows

i would like to compile a project using the apache portable runtime libraries (APR) and cmake. It all looks good when running along with linux (as there i can use the apr-1-config shell script). Nevertheless, in windows it looks like cmake does not bind or link the included files correctly. I've tried some different methods, like importing the libapr-1.lib as static library or just target_link_library all stuff, yet nothing seems to work. I always get the
error LNK2019: unresolved external symbol
linker errors when compiling using visual studio. It does not matter which function i am calling, as an example i am calling apt_pool_create, as it does not require any parameters.
I am still wondering as visual studio is finding the files with IntelliSense and showing me all documentations inline. Also the compiler does not fail to build when an apt_pool* pointer object is defined and initialized with NULL.
Maybe anyone does know why there are these linker problems. Following are some snippets out of the CMakeLists.txt files:
CMakeLists.txt (partial)
# Include unimrcp requirements (apr package)
IF(WIN32) # Search APR in windows
INCLUDE(${PROJECT_SOURCE_DIR}/cmake_modules/FindAPR_windows.cmake)
ELSE(WIN32) # Search APR in unix
INCLUDE(${PROJECT_SOURCE_DIR}/cmake_modules/FindAPR_unix.cmake)
ENDIF(WIN32)
# Set link libraries
SET(TARGET_LINK_LIBS
${APR_LIBRARIES}
${APRUTIL_LIBRARIES}
${PTHREADS}
)
SET(CLIENT_SOURCES ...)
SET(CLIENT_HEADERS ...)
# Include intermediary files
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${APR_INCLUDE_DIR}
${APRUTIL_INCLUDE_DIR}
)
# Add executable and link libraries
ADD_EXECUTABLE(${CLIENT_TARGET} src/main.cpp ${CLIENT_SOURCES} ${CLIENT_HEADERS})
TARGET_LINK_LIBRARIES(${CLIENT_TARGET} ${TARGET_LINK_LIBS})
The CLIENT_TARGET is just a predefined target name for output.
[For windows i am using following FindAPR.cmake module (the FindAPR_windows.cmake file)](
https://svn.apache.org/repos/asf/incubator/celix/trunk/cmake/modules/FindAPR.cmake).
For linux i am using following FindAPR.cmake module (the FindAPR_unix.cmake file).
It searches for apr-1-config and executes the shell script.
In linux my APR_LIBRARIES variable looks like this:
-L/usr/lib;-lapr-1
Windows is directly using the library with its path:
{path_to_lib}/libapr-1.lib
CMake does not announce any errors for linking, as mentioned above Visual Studio does give me the LNK2019 errors when calling for any apr function.
Maybe someone does have a hint for this problem?

Resources