cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.24k stars 7.06k forks source link

Error "Definition of dllimport function not allowed" for clear project #20400

Open BonBonSlick opened 4 years ago

BonBonSlick commented 4 years ago

Steps to Reproduce:

  1. Install VS 2019 Community
  2. Install python v 2.7.17
  3. unpack cocos
  4. cocos new test -l cpp
  5. compile project
  6. see the error list

First error of 3 leads to https://github.com/irontec/Ikasesteka/blob/master/Ikasesteka/cocos2d/cocos/base/CCConsole.h#L60

rh101 commented 4 years ago

If you used the default Visual Studio project in the proj.win32 folder, then that may be the problem.

Create a new project with CMake. Install CMake on your system, then follow the instructions here: https://github.com/cocos2d/cocos2d-x/tree/v3/cmake

For VS2019, you can use this to generate the Win32 project:

mkdir win32build
cd .\win32build
cmake .. -G"Visual Studio 16 2019" -Tv142 -A Win32
BonBonSlick commented 4 years ago

I use now cocos2d-x v 4.0 as it outperforms v 3.17. Creating a clear win 32 project with Cmake displays now other default errors in error log.

Windows 10 VS 2019


Severity    Code    Description Project File    Line    Suppression State   Suppression State

Error (active)  E0130   expected a '{'  test    C:\Cocos_2D\Games\test\cocos2d\cocos\base\CCConsole.h   63      

Error (active)  E0130   expected a '{'  test    C:\Cocos_2D\Games\test\cocos2d\cocos\base\ccUTF8.h  66      
rh101 commented 4 years ago

Do a test:

  1. Open a command prompt
  2. Change directory to the cocos2d cpp-tests folder, for instance: [installation path]\tests\cpp-empty-test
  3. Type each of these lines in the command window:
    mkdir win32build
    cd .\win32build
    cmake .. -G"Visual Studio 16 2019" -Tv142 -A Win32
  4. Now go into the win32build folder that was created at step 3, and open the solution file cpp-empty-test.sln in Visual Studio 2019.
  5. Right click the cpp-empty-test project and set it as your start-up project.
  6. Build and run.

See if that works. If it does, then the issue you're having is in your own code.